-
Notifications
You must be signed in to change notification settings - Fork 56
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
yield.ReturnAsync inside ParallelForEachAsync #45
Comments
I've exactly the same issue... |
Good try, but this is simply an unsupported scenario with concurrent producers. IEnumerable<...> Stream(...)
{
Parallel.ForEach(... =>
{
yield return ...; // won't compile
}
yield return ...; // will compile
} The Since this library mimics a C# language feature, it cannot impose similar restrictions on using the variable IAsyncEnumerable<...> Stream(...)
{
return new AsyncEnumerable<...>(async yield => // 'yield' is a variable
{
await ....ParallelForEachAsync(async ...=>
{
// 'yield' gets captured in the closure, that's why you can use it, but must not
await yield.ReturnAsync(...);
}, ...);
});
} If you try to use C# 3.0 and async streams, it won't work either. So this is something you have to be aware of. Concurrent producer/consumer pattern with limiters is a slightly more complex problem, and is not available as an extension method in this library. I posted a possible solution on StackOverflow. One thing I can recommend is to swap methods in your case - the producer uses |
P.S. this is a duplicate of #44 |
How about using SemaphoreSlim to ensure only 1 active call to
yield.Returning is happening at anyone time?
I tried and it seems to work just fine. But I'll have a look at your links
later.
ons. 26. jun. 2019 18.59 skrev Serge Semenov <[email protected]>:
… P.S. this is a duplicate of #44
<#44>
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#45?email_source=notifications&email_token=ACZKVRBUMV52VQDVS3IIP2TP4ON5HA5CNFSM4H3ROQJ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYUFNKY#issuecomment-505960107>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACZKVRFKN7CISMFUVZPXMGDP4ON5HANCNFSM4H3ROQJQ>
.
|
The use of |
We have trouble using ParallelForEachAsync to start a number of parallel running async webrequests (actually they are Azure Blob Storage retrievals) and have the result being returned using yield.ReturnAsync.
The problem is that before the first result is returned, multiple parallel webrequests have been started and also completed, yet only the last of the results are returned to the consumer (that iterates using ForEachAsync).
The producer:
The consumer:
What did we do wrong?
The text was updated successfully, but these errors were encountered: