Method ToAwaitable
ToAwaitable()
Creates an Awaitable_1 that completes when the operation completes.
Declaration
public Awaitable<TObject> ToAwaitable()
Returns
| Type | Description |
|---|---|
| Awaitable<TObject> | An awaitable that completes with the operation's result, or throws on failure. |
Remarks
Unlike Task, failure throws an AsyncOperationHandleException<TObject> instead of resolving
with a default or partial Result. Its Handle carries a
reference you must release (via e.Handle.Release()) if you still need to inspect Status or a partial result.
The returned Awaitable_1 can only be awaited once. Don't await the same handle from multiple call sites
unless nothing else releases it - whichever awaiter hits a failure or cancellation first releases the handle out from
under the others. For multiple independent consumers, hold the handle and use Completed instead.
ToAwaitable(CancellationToken)
Creates an Awaitable_1 that completes when the operation completes, or is
canceled when cancellationToken is canceled.
Declaration
public Awaitable<TObject> ToAwaitable(CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancellationToken | Token that cancels the awaitable and releases this handle. |
Returns
| Type | Description |
|---|---|
| Awaitable<TObject> | An awaitable that completes with the operation's result, or throws on failure or cancellation. |
Remarks
See the parameterless ToAwaitable() for failure and single-use semantics. This overload also releases the handle on cancellation, so it assumes sole ownership of the reference - a lifetime-scoped token (e.g. destroyCancellationToken via ToAwaitable(MonoBehaviour)) can therefore replace a manual release call. Expected to be canceled on the main thread.
ToAwaitable(MonoBehaviour)
Creates an Awaitable_1 tied to owner's destruction - shorthand
for ToAwaitable(owner.destroyCancellationToken).
Declaration
public Awaitable<TObject> ToAwaitable(MonoBehaviour owner)
Parameters
| Type | Name | Description |
|---|---|---|
| MonoBehaviour | owner | The component whose destruction cancels the awaitable and releases this handle. |
Returns
| Type | Description |
|---|---|
| Awaitable<TObject> | An awaitable that completes with the operation's result, or throws on failure or cancellation. |
Remarks
Destroy-scoped, not Disable-scoped: destroyCancellationToken only cancels on
destruction. For a load that repeats across OnEnable/OnDisable, use a
CancellationTokenSource created and canceled per cycle instead - see ToAwaitable(CancellationToken).