From 7f582e5e29228179cacee450da471d41ea125dd8 Mon Sep 17 00:00:00 2001 From: hadashiA Date: Fri, 27 Oct 2023 14:51:52 +0900 Subject: [PATCH] Update README --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 487aec0..d1cacac 100644 --- a/README.md +++ b/README.md @@ -336,6 +336,18 @@ if (isCanceled) Note: Only suppress throws if you call directly into the most source method. Otherwise, the return value will be converted, but the entire pipeline will not suppress throws. +Some features that use Unity's player loop, such as `UniTask.Yield` and `UniTask.Delay` etc, determines CancellationToken state on the player loop. +This means it does not cancel immediately upon `CancellationToken` fired. + +If you want to change this behaviour, the cancellation to be immediate, set the `cancelImmediately` flag as an argument. + +```csharp +await UniTask.Yield(cancellationToken, cancelImmediately: true); +``` + +Note: Setting `cancelImmediately` to true and detecting an immediate cancellation is more costly than the default behavior. +This is because it uses `CancellationToken.Register`; it is heavier than checking CancellationToken on the player loop. + Timeout handling --- Timeout is a variation of cancellation. You can set timeout by `CancellationTokenSouce.CancelAfterSlim(TimeSpan)` and pass CancellationToken to async methods. @@ -363,7 +375,7 @@ If you want to use timeout with other source of cancellation, use `CancellationT ```csharp var cancelToken = new CancellationTokenSource(); -cancelButton.onClick.AddListener(()=> +cancelButton.onClick.AddListener(() => { cancelToken.Cancel(); // cancel from button click. });