Vixen
02b45cc4
csharp
public readonly struct Coroutine

What an async gameplay routine returns: a unit of work that lives across frames.

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

Remarks

async Coroutine Fade() { await Seconds(0.5f); while (Alpha > 0f) { Alpha -= Time.DeltaSeconds; await NextFrame(); } } and Run(Fade()) to start it.

Why a type of its own rather than ValueTask. Two reasons, and neither is decoration. The first is the builder: CoroutineMethodBuilder is attached here, so every async Coroutine method gets a pooled state machine without the author writing an attribute on each one. The second is that a coroutine is a thing you start and forget, and ValueTask's surface — .Result, .AsTask(), .GetAwaiter().GetResult() — is a set of ways to block the loop thread. None of them are here.

A coroutine is consumed exactly once. Either await it or hand it to Run, never both, and never twice. The state machine behind it goes back to a pool the moment its result is read, and reading a second time reads whatever took its place. This is ValueTask's rule and UniTask's rule; it is inherent to pooling rather than a choice any of the three made.

Fields and properties (1)

  • public static Coroutine Completed

    A coroutine that has already finished.

Methods (2)

  • public ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter GetAwaiter()

    Makes this awaitable.

  • public static Coroutine WhenAll(params Coroutine[] coroutines)

    Finishes when every one of them has finished.

Used by (10)

  • BehaviorVixen.Engine
  • CoroutineAllocationTestsVixen.Engine.Tests
  • CoroutineMethodBuilderVixen.Engine
  • CoroutineSchedulerVixen.Engine
  • CoroutineTestsVixen.Engine.Tests
  • HoldsAResourceVixen.Engine.Tests
  • NestsACoroutineVixen.Engine.Tests
  • SequencerVixen.Engine.Tests
  • StartsACoroutineVixen.Engine.Tests
  • WaitsTenSecondsVixen.Engine.Tests