Use Channel Instead of BufferBlock#5123
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5123 +/- ##
==========================================
- Coverage 75.66% 75.55% -0.11%
==========================================
Files 993 995 +2
Lines 178168 179316 +1148
Branches 19122 19298 +176
==========================================
+ Hits 134802 135487 +685
- Misses 38143 38564 +421
- Partials 5223 5265 +42
|
Codecov Report
@@ Coverage Diff @@
## master #5123 +/- ##
==========================================
- Coverage 75.66% 73.68% -1.98%
==========================================
Files 993 1022 +29
Lines 178168 190353 +12185
Branches 19122 20473 +1351
==========================================
+ Hits 134802 140264 +5462
- Misses 38143 44557 +6414
- Partials 5223 5532 +309
|
|
Thanks @eerhardt! I'll make similar changes to the other items and will mark this PR ready. |
|
I think you can remove this line as well: |
| // We are under capacity. Try to get some more. | ||
| int got = _toConsume.Receive(); | ||
| if (got == 0) | ||
| var hasReadItem = _toConsumeChannel.Reader.TryRead(out int got); |
There was a problem hiding this comment.
Previously _toConsume.Receive() would block the thread until something was available. But now TryRead will return false immediately if something wasn't available. In that case, we will keep spinning in the while loop and checking the reader constantly.
It might make sense to keep the previous behavior and block the thread until _toConsumeChannel has an item available, so we aren't wasting CPU cycles spinning here.
I don't believe this comment has been addressed yet: |
@eerhardt I may need some guidance on the best way to block the thread there. 😃 Would using the |
|
I believe you can call // Get a TCS to represent the receive operation and wait for it to complete.
// If it completes successfully, return the result. Otherwise, throw the
// original inner exception representing the cause. This could be an OCE.
Task<TOutput> task = ReceiveCore(source, false, timeout, cancellationToken);
try
{
return task.GetAwaiter().GetResult(); // block until the result is available
} |
|
@eerhardt Updated to use |
|
@jwood803 Thank you for your contribution. I am merging the PR now. |
Updates for #4482.
@eerhardt I took a shot at a single replacement to make sure it looks good before continuing. Does this look good or am I missing anything?