Vixen
02b45cc4
csharp
public sealed class CoroutineScheduler

Where suspended coroutines wait, and the thing that decides when they carry on.

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

Remarks

It is a queue per resume point, drained on the loop thread, and nothing else. There is no timer, no thread pool and no synchronisation context anywhere in a coroutine's life: a continuation goes into a list, a drain at a known frame point walks that list in the order things were added, and whatever is ready runs. That is what makes a coroutine as deterministic as a system — the same sequence of frame deltas produces the same sequence of resumptions, which the determinism exit criterion of this phase requires and which nothing built on Task and the thread pool could promise.

Nothing resumes in the frame it suspended in. Every wait records the tick it was made on and becomes eligible on the next one, so await Seconds(0f) costs a frame and while (true) await NextFrame(); is a loop rather than a hang. The tick is the frame for three of the resume points and the fixed step for FixedStep, which is why a frame owing three steps resumes a step-waiting coroutine three times.

Steady state allocates nothing. The waiting entries are structs in a reused list; the continuation delegate is the one the pooled state machine box caches; the state machines themselves come from PoolingAsyncValueTaskMethodBuilder's pool; and the bookkeeping object behind a running coroutine comes from a free list here. A behaviour that starts a coroutine every frame for an hour allocates for the first few and then stops. That is measured, not asserted — see CoroutineAllocationTests.

Fields and properties (6)

  • public long Frame

    How many frames have begun.

  • public long Step

    How many fixed steps have begun.

  • public GameTime Time

    The clock as of the last BeginFrame.

  • public ResumePoint CurrentPoint

    The resume point currently being drained, and Update when none is. This is what an await NextFrame() with no explicit point means.

  • public int RunningCount

    How many coroutines have been started and not yet finished.

  • public Action<Exception>? UnhandledException

    What to do with an exception that escapes a coroutine. rethrows it out of the drain that observed it.

Methods (11)

Used by (14)

  • BehaviorVixen.Engine
  • BehaviorStoreVixen.Engine
  • ClockVixen.Engine.Tests
  • CoroutineAllocationTestsVixen.Engine.Tests
  • CoroutineAwaitableVixen.Engine
  • CoroutineEndOfFrameSystemVixen.Engine
  • CoroutineFixedStepSystemVixen.Engine
  • CoroutineHandleVixen.Engine
  • CoroutineLateUpdateSystemVixen.Engine
  • CoroutineTestsVixen.Engine.Tests
  • CoroutineUpdateSystemVixen.Engine
  • EngineLoopVixen.Engine
  • RunningCoroutineVixen.Engine
  • TypeRegistrationVixen.Editor.App.Tests