Open-NET-Libraries / Open.ChannelExtensions

A set of extensions for optimizing/simplifying System.Threading.Channels usage.
https://open-net-libraries.github.io/Open.ChannelExtensions/api/Open.ChannelExtensions.Extensions.html#methods
MIT License
401 stars 25 forks source link

Fix OperationCanceledException catching #41

Closed mrak1990 closed 3 months ago

mrak1990 commented 3 months ago

Fix #40

electricessence commented 3 months ago

If you read the lines above, the "cancellation" can occur in the Write. The entire point of this method is to respond to a cancellation and NOT THROW. Cancellation is always caused upstream, there's no way to really know when it's an OperationCancelledException if the user intended that to bubble up.

If you actually use these methods, instead of a try-catch, just call cancellationToken.ThrowIfCancellationRequested(); if you're intention is to propagate the exception.