You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Basically, they're using AsyncEnumerable<T>.ForEachAsync, but rather than producing items serially, they tried to produce concurrently by creating multiple concurrent generator tasks within the delegate that's passed into the AsyncEnumerable constructor. In other words, they were trying to use this library for the multi producer, single consumer pattern.
The problem is that the incorrect usage did not result in an error, but instead their program hung, and they didn't understand why. I believe it's related to calling Yield.ReturnAsync multiple times, before the previous task returned by ReturnAsync is in a completed state, causing the last call to overwrite information from the previous calls.
I believe if Yield.ReturnAsync throws an InvalidOperationException when it detects a call when the previous call is not completed, then it would allow your users to more quickly detect problems in their own code.
The text was updated successfully, but these errors were encountered:
@zivkan, thanks for the suggestion. You are absolutely right about the sequential producer pattern. This might not be obvious to everyone, however, there are many more standard types that don't support concurrent programming model - take Dictionary<,> for example.
It is possible to add protection from parallel produce attempts, but it comes with a performance cost that would impact the majority of normal cases. On the other hand, we can update the documentation to explicitly call out this point.
I completely understand the performance concern. I think a helper method sounds best, but docs are good too. But honestly, I don't use your library, I was just trying to help out after investigating an interesting Stack Overflow question :)
A user of your library posted this question on stack overflow.
Basically, they're using
AsyncEnumerable<T>.ForEachAsync
, but rather than producing items serially, they tried to produce concurrently by creating multiple concurrent generator tasks within the delegate that's passed into theAsyncEnumerable
constructor. In other words, they were trying to use this library for the multi producer, single consumer pattern.The problem is that the incorrect usage did not result in an error, but instead their program hung, and they didn't understand why. I believe it's related to calling
Yield.ReturnAsync
multiple times, before the previous task returned by ReturnAsync is in a completed state, causing the last call to overwrite information from the previous calls.I believe if
Yield.ReturnAsync
throws an InvalidOperationException when it detects a call when the previous call is not completed, then it would allow your users to more quickly detect problems in their own code.The text was updated successfully, but these errors were encountered: