Created
July 16, 2019 05:48
-
-
Save natenho/ff8ba5f61c10b31cf802758fd6b7fa23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async Task ProcessMultipleAtOnce<T>(int maxDegreeOfParallelism, IEnumerable<T> items, Func<T, Task> func) | |
{ | |
var actionBlock = new ActionBlock<T>(func, new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism }); | |
foreach (T item in items) | |
{ | |
await actionBlock.SendAsync(item); | |
} | |
actionBlock.Complete(); | |
await actionBlock.Completion; | |
} | |
// https://stackoverflow.com/a/14076323/1987788 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment