Where to use SuppressCancellationThrow #590
Replies: 1 comment 3 replies
-
Unfortunately, cancellations cannot be propagated without throwing. Upvote the csharplang issue if you would like it natively supported in the language.
Yes and no. Under the hood, each async function traps throws. When you await the returned |
Beta Was this translation helpful? Give feedback.
-
If I start a chain of async calls, where do I need to put SuppressCancellationThrow if I don't want to try/catch at my top level when a cancellation happens? Does SuppressCancellationThrow trap throws under the covers and propagate a return value?
Also is there a way to just never throw and just check the token yourself as I would prefer not to have to use SuppressCancellationThrow.
async UniTask<bool> DoIt(){ await UniTask.Delay(1000, cancellationToken: token); return token.IsCancellationRequested);
Cheers.
Beta Was this translation helpful? Give feedback.
All reactions