Vixen
02b45cc4
csharp
public struct CoroutineMethodBuilder

Builds the state machine behind an async Coroutine method.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

Every member forwards to PoolingAsyncValueTaskMethodBuilder, which is the whole point of the type existing. That builder rents the state machine box from a pool and returns it when the result is read, so a coroutine started every frame for an hour allocates once. Doing this by hand — a pool, an IValueTaskSource, a version token — is what UniTask had to write, because Unity's runtime had no such builder. .NET has one, and the honest amount of work here is to forward to it.

It exists at all only so that Coroutine can be the return type. A builder's Task property has to have the method's return type, so a wrapper type needs a wrapper builder; there is no way to say "use the pooling builder, but call the result something else".

Fields and properties (1)

  • public Coroutine Task

    The coroutine the method returns.

Methods (7)

  • public static CoroutineMethodBuilder Create()

    Creates a builder.

  • public void Start<TStateMachine>(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine

    Runs the state machine up to its first suspension.

  • public void SetStateMachine(IAsyncStateMachine stateMachine)

    Associates a boxed state machine with this builder.

  • public void SetResult()

    Completes the coroutine.

  • public void SetException(Exception exception)

    Faults the coroutine.

  • public void AwaitOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine

    Schedules the state machine to continue when an awaiter completes.

  • public void AwaitUnsafeOnCompleted<TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : ICriticalNotifyCompletion where TStateMachine : IAsyncStateMachine

    Schedules the state machine to continue, without flowing the execution context.

Used by (1)

  • CoroutineVixen.Engine