Function coroutine

  • Creates a coroutine for the specified generator function that is bound to the target. The coroutine can be updated each frame by calling Coroutine.continue.

    Type Parameters

    • T
    • K extends object

    Parameters

    • targetOrGenerator: K | (() => Generator<T, any, any>)

      The this pointer to bind the generator to, or the generator if the generator should be called unbound.

    • Optionalgenerator: ((this: K) => Generator<T, any, any>)

      The generator.

        • (this): Generator<T, any, any>
        • Parameters

          • this: K

          Returns Generator<T, any, any>

    • OptionalonFinalize: (() => void)

      An optional lambda that is called when the coroutine is finalized.

        • (): void
        • Returns void

    Returns Coroutine<T>

    Coroutine

    If the generator is not intended to be bound to a this pointer. It can be passed as the first argument. To get type safety pass the lambda with a type declaring this pointer:

    coroutine(this, (this:MyClass) => { ... })