Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using ParallelForEachAsync() for non-CPU-intensive tasks #69

Open
DumboJetEngine opened this issue Apr 21, 2022 · 0 comments
Open

Using ParallelForEachAsync() for non-CPU-intensive tasks #69

DumboJetEngine opened this issue Apr 21, 2022 · 0 comments

Comments

@DumboJetEngine
Copy link

DumboJetEngine commented Apr 21, 2022

I would like to use a parallel loop for N number of calls to a service, to execute them in batches, and avoid DoS-ing the service.
I had previously created my own version of the loop, using Task.WhenAny() and Task.WhenAll(), but then I needed that in multiple places and thought I should find myself a library for it (unfortunately, I don't use .NET 6 yet, so I don't have its features).

Looking at your ParallelForEachAsync method:
https://github.com/Dasync/AsyncEnumerable/blob/master/src/Extensions/ParallelForEachExtensions.cs#L279
I see that it uses Task.Run() which would be using a new thread.
But I guess that this could be avoided in my case, couldn't it?
So, in other words, your library is not optimized for my use-case, correct?
Or perhaps this code is only used to prevent deadlocks?
Let me know if I am missing anything. :)

I wonder if the Parallel.ForEachAsync() method in .NET 6 works the same way as your library:
https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.parallel.foreachasync?view=net-6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant