Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Execute implementation

View gist:4969559
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
public IEnumerable<Row> Execute(IEnumerable<Row> rows)
{
var blockingCollection = new BlockingCollection<Row>();
var count = _operations.Count;
if (count == 0)
{
yield break;
}
var tasks = _operations.Select(currentOp =>
Task.Factory.StartNew(() =>
{
try
{
foreach (var row in currentOp.Execute(null))
{
blockingCollection.Add(row);
}
}
finally
{
if (Interlocked.Decrement(ref count) == 0)
{
blockingCollection.CompleteAdding();
}
}
}
)
).ToArray();
foreach (var row in blockingCollection.GetConsumingEnumerable())
{
yield return row;
}
Task.WaitAll(tasks); // raise any exception that were raised during execution
}

Works great. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.