Options
All
  • Public
  • Public/Protected
  • All
Menu

ajeeb-coroutines

Index

Classes

Type aliases

Combinator Functions

Coroutine Functions

Other Functions

Type aliases

Coroutine

Coroutine: Generator<any>

A Coroutine is a regular ES6 Generator returned by a generator function.

function* simpleCoroutine() {
  console.log('hello')
  yield
  console.log('world')
}

let coro : Coroutine = simpleCoroutine()

CoroutineOrFunction

CoroutineOrFunction: Coroutine | ((...any: any) => Coroutine)

Some functions accept either a Coroutine or a function that can be called with no arguments to produce a Coroutine. This enables passing function* in addition to instantiated Coroutines.

function* namedCoroutine() { ... }
const sched = new coro.Schedule()
// invoking namedCoroutine produces a Coroutine instance
sched.add(namedCoroutine())
// function* literal is not a Coroutine instance, but can
// be invoked to produce one. It is a CoroutineOrFunction.
sched.add(function* () { ... })

Combinator Functions

waitAll

waitFirst

  • Returns a coroutine that waits for the first coroutine of coros to complete.

    Parameters

    Returns Coroutine

    When complete, returns the value returned by the first completed coroutine in coros.

Coroutine Functions

wait

  • wait(seconds: number, clock?: () => number): Coroutine
  • Wait for a number of seconds.

    see

    setClock

    Parameters

    • seconds: number

      How many seconds to wait

    • clock: () => number = ...

      A function that returns the elapsed application time in seconds, defaults to the function assigned by setClock

        • (): number
        • Returns number

    Returns Coroutine

waitFrames

waitUntil

  • waitUntil(f: (...any: any) => boolean): Coroutine
  • Wait until a function f returns true.

    Parameters

    • f: (...any: any) => boolean

      A function to execute every frame. When f returns truthy this coroutine completes.

        • (...any: any): boolean
        • Parameters

          • Rest ...any: any

          Returns boolean

    Returns Coroutine

waitWhile

  • waitWhile(f: (...any: any) => boolean): Coroutine
  • Wait while a function f returns true.

    Parameters

    • f: (...any: any) => boolean

      A function to execute every frame. When f returns falsey this coroutine completes.

        • (...any: any): boolean
        • Parameters

          • Rest ...any: any

          Returns boolean

    Returns Coroutine

Other Functions

setClock

  • setClock(f: () => number): void
  • Sets a new clock function.

    The clock function returns the elapsed application time in seconds. It is called by some coroutines to measure the passage of time. defaults to performance.now() / 1000

    Parameters

    • f: () => number

      New clock function

        • (): number
        • Returns number

    Returns void

Generated using TypeDoc