Various improvements
This commit is contained in:
@ -66,5 +66,26 @@ namespace TransportGame.Utils
|
||||
if (Success.HasValue && !Success.Value)
|
||||
throw new Exception("Task failed", thrownException);
|
||||
}
|
||||
|
||||
public static IEnumerable InParallel(params IEnumerable[] funcs)
|
||||
{
|
||||
// Obtain iterators
|
||||
var iterators = funcs.Select(enumerable => enumerable.GetEnumerator()).ToArray();
|
||||
|
||||
// Execute a slice of each
|
||||
bool stop;
|
||||
do
|
||||
{
|
||||
stop = true;
|
||||
|
||||
foreach (var it in iterators)
|
||||
if (it.MoveNext())
|
||||
{
|
||||
yield return it.Current;
|
||||
stop = false;
|
||||
}
|
||||
|
||||
} while (!stop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user