A coroutine schedule.

Coroutines are added to a schedule with Schedule.add and all scheduled coroutines are advanced with Schedule.tick.

Implemented as an optimized double-ended linked list.

Constructors

Properties

Methods

Constructors

Properties

back: any
front: any
size: number

Methods

  • Schedules a coroutine for evaluation.

    Future calls to Schedule.tick will run coro up to its next yield until it is completed, after which it will be removed from the schedule.

    As a convenience if coro is a generator function and not a generator, it will be invoked with no arguments to produce a generator.

    Parameters

    • coro: GeneratorFunction | Generator<any, any, any>

      Coroutine to add

    Returns Generator<unknown, any, unknown>

    See

    Generator Documentation

    Example

    function* coroutineFunction() { ... }
    const SCHED = new Schedule()
    SCHED.add(coroutineFunction()) // this works
    SCHED.add(coroutineFunction) // so does this
  • Remove a single coroutine from the schedule.

    If coro is paused in a try statement this method does not trigger its finally handler. If you want logic in the finally handler to run you must call Generator.return on coro yourself.

    Parameters

    • coro: Generator<any, any, any>

      Coroutine to remove from schedule

    Returns void

    See

    Generator.return

    Example

    function* foo() { ... }
    const f = foo()
    const SCHED = new Schedule()
    SCHED.add(f)
    SCHED.tick() // runs foo to next yield
    SCHED.remove(f)
    SCHED.tick() // foo is not run
  • Discards all scheduled coroutines.

    Similar to Schedule.remove this method does not trigger finally handlers.

    Returns void

  • Advances all scheduled coroutines once.

    Each coroutine added with Schedule.add is advanced with Generator.next, causing it to run up to its next yield statement. Finished coroutines are removed from the schedule.

    Returns void