ICancellationTokenSource #54460
-
In the same vein as Reason: In my ProtoPromise library, I have a custom Async iterators added |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Thanks for the suggestion, but we've discussed this before and don't want to do it. CancellationToken has a strong guarantee that once it transitions to having cancellation requested, it'll never transition back, and such use would break that guarantee. You can, of course, reuse a CTS as many times as you'd like if it hasn't yet had cancellation requested (and if it has, the associated costs almost always are orders of magnitude larger than what you'd potentially save by pooling), subject to whatever guarantees your own code provides, and we added TryReset in .NET 6 to make that easier, in particular in the face of timeouts. |
Beta Was this translation helpful? Give feedback.
Thanks for the suggestion, but we've discussed this before and don't want to do it. CancellationToken has a strong guarantee that once it transitions to having cancellation requested, it'll never transition back, and such use would break that guarantee. You can, of course, reuse a CTS as many times as you'd like if it hasn't yet had cancellation requested (and if it has, the associated costs almost always are orders of magnitude larger than what you'd potentially save by pooling), subject to whatever guarantees your own code provides, and we added TryReset in .NET 6 to make that easier, in particular in the face of timeouts.