Struct PromiseMethodBuilder<T>
- Namespace
- MarymoorStudios.Core.Promises
- Assembly
- MarymoorStudios.Core.Promises.dll
Enables the async keyword for methods that return a Promise<T>.
public struct PromiseMethodBuilder<T>
Type Parameters
TThe type of the value produced by a successful outcome.
- Inherited Members
Properties
Task
A promise for the final outcome of an async methods.
public Promise<T> Task { get; }
Property Value
- Promise<T>
Remarks
Called by the compiler generated code at the callsite of an async method to retrieve a promise for the methods eventual outcome.
Methods
AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter, ref TStateMachine)
Schedule the resumption of an async method during a blocking await point for awaitables that only implement the base INotifyCompletion notification style.
public void AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine
Parameters
awaiterTAwaiterThe awaiter of the awaitable this async method is blocking on.
stateMachineTStateMachineThe state machine that captures the resumable state of this async method.
Type Parameters
TAwaiterThe type of the awaiter of the awaitable this async method is blocking on.
TStateMachineThe anonymous type generated by the compiler to captured stack variables and provide resumption logic for each await point.
AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter, ref TStateMachine)
Schedule the resumption of an async method during a blocking await point for awaitables that also implement the newer ICriticalNotifyCompletion notification style.
public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : ICriticalNotifyCompletion where TStateMachine : IAsyncStateMachine
Parameters
awaiterTAwaiterThe awaiter of the awaitable this async method is blocking on.
stateMachineTStateMachineThe state machine that captures the resumable state of this async method.
Type Parameters
TAwaiterThe type of the awaiter of the awaitable this async method is blocking on.
TStateMachineThe anonymous type generated by the compiler to captured stack variables and provide resumption logic for each await point.
Create()
Factor method for this builder.
public static PromiseMethodBuilder<T> Create()
Returns
- PromiseMethodBuilder<T>
A new builder.
Remarks
This is used by the generated code to create a new instance of the builder when an async method's is first pushed on the stack.
SetException(Exception)
Resolve the return value with a failed outcome.
public void SetException(Exception ex)
Parameters
exExceptionThe error that caused the failure.
Remarks
Called by the compiler generated code at any failure exit point from the async method to inform callers of the final outcome.
SetResult(T)
Resolve the return value with a successful outcome.
public void SetResult(T value)
Parameters
valueT
Remarks
Called by the compiler generated code at any successful exit point from the async method to inform callers of the final outcome.
SetStateMachine(IAsyncStateMachine)
Hoists the state machine into the heap to be saved across a blocking await.
public readonly void SetStateMachine(IAsyncStateMachine stateMachine)
Parameters
stateMachineIAsyncStateMachineThe stack frame instance to be saved.
Start<TStateMachine>(ref TStateMachine)
Starts the async method's state machine.
public readonly void Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine
Parameters
stateMachineTStateMachineAn instance of
TStateMachinefor the current stack frame.
Type Parameters
TStateMachineThe anonymous type generated by the compiler to captured stack variables and provide resumption logic for each await point.
Remarks
Note that stateMachine is passed by ref here because it has been allocated
on the stack frame at this point. It won't be hoisted to the heap (causing a heap allocation) until and
unless at least one of the await points actually blocks. This is an optimization to avoid unnecessary heap
allocations if all awaitables turn out to already ben resolved (a common case in some circumstances).