Skip to content

Commit 1a4214c

Browse files
authored
Update README.MD
1 parent bb4359b commit 1a4214c

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

README.MD

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ async void Start()
128128
`Await` actually contains many shortcut functions to streamline your code.
129129

130130
## ConfigureAwait
131-
Just like with `Task`s, UnityAsync `Continuation<T>`s can be configured. You can set the scheduler (Update, LateUpdate, FixedUpdate) and also link its lifespan to a `UnityEngine.Object` or `CancellationToken`. Anything after the `await` line will not be reached if the `Continuation` was cancelled (either by its linked `UnityEngine.Object` being destroyed or a cancellation requested on the token.
131+
Just like with `Task`s, UnityAsync `IAwaitInstruction`s can be configured. You can set the scheduler (Update, LateUpdate, FixedUpdate) and also link its lifespan to a `UnityEngine.Object` and/or `CancellationToken`. Anything after the `await` line will not be reached if the `IAwaitInstruction`'s linked `UnityEngine.Object` was destroyed. If a cancellation was requested, an exception is thrown after the `await` line, which can be handled as you would when a `Task` is cancelled.
132132
```c#
133133
using UnityEngine;
134134
using UnityAsync;
@@ -143,7 +143,19 @@ async void Start()
143143
// time is evaluated every fixed update
144144
await Await.Seconds(10).ConfigureAwait(this, FrameScheduler.FixedUpdate);
145145

146-
// ...we are now in fixed update (assuming this MonoBehaviour was not destroyed)
146+
// ... if the calling MonoBehaviour was destroyed, we won't get this far
147+
// if it is still alive, we'll be in FixedUpdate
148+
149+
var c = new CancellationSource(100);
150+
151+
try
152+
{
153+
await Await.Seconds(10).ConfigureAwait(c.Token);
154+
}
155+
catch(OperationCancelledException)
156+
{
157+
// exception will be caught here after 100ms
158+
}
147159
}
148160

149161
...

0 commit comments

Comments
 (0)