Hyperlinkv0.8.0-beta.28

Scheduler

Scheduler.MixedSchedulerclasseffect/Scheduler.ts:141
MixedScheduler

Provides a scheduler implementation that batches queued tasks and dispatches them by priority.

When to use

Use when you need the default runtime scheduler directly, including a scheduler that batches queued work by priority and preserves FIFO order within each priority.

Details

MixedScheduler supports synchronous and asynchronous execution modes, uses operation counts to decide when fibers should yield, and is the default scheduler implementation.

schedulers
export class MixedScheduler implements Scheduler {
  readonly executionMode: "sync" | "async"
  readonly setImmediate: (f: () => void) => () => void

  constructor(
    executionMode: "sync" | "async" = "async",
    setImmediateFn: (f: () => void) => () => void = setImmediate
  ) {
    this.executionMode = executionMode
    this.setImmediate = setImmediateFn
  }

  /**
   * Returns whether the fiber has reached its operation budget and should yield.
   *
   * **When to use**
   *
   * Use to decide whether a fiber should yield after consuming its current
   * operation budget.
   *
   * @since 2.0.0
   */
  shouldYield(fiber: Fiber.Fiber<unknown, unknown>) {
    return fiber.currentOpCount >= fiber.maxOpsBeforeYield
  }

  /**
   * Creates a dispatcher that schedules work through this scheduler.
   *
   * **When to use**
   *
   * Use when you need a standalone dispatcher from a scheduler instance, for
   * example in tests that enqueue tasks and then flush them deterministically.
   *
   * @since 4.0.0
   */
  makeDispatcher() {
    return new MixedSchedulerDispatcher(this.setImmediate)
  }
}
Referenced by 3 symbols