Taos API Reference
    Preparing search index...

    Class Signal<A>

    A typed, multi-listener event bound to an object property. Being a property rather than a string-keyed event makes the set of events a class emits explicit, removes misspelled-name bugs, and lets TypeScript check listener argument types end-to-end:

    class Health extends Component {
    readonly damaged = new Signal<[amount: number, source: GameObject]>();
    readonly died = new Signal();

    applyDamage(amount: number, source: GameObject): void {
    this.hp -= amount;
    this.damaged.emit(amount, source); // emit('5') is a compile error
    if (this.hp <= 0) {
    this.died.emit();
    }
    }
    }

    connect returns an unsubscribe function; components should prefer Component.listen, which disconnects automatically when the component detaches.

    Emit semantics:

    • Listeners run synchronously, in connection order, against a snapshot of the listener list — connecting or disconnecting during an emit never affects the in-flight emit.
    • A listener that throws does not stop the remaining listeners: the error is routed to Signal.errorHandler (default console.error).
    • queueEmit defers the emit to Signal.flushQueued, which the engine runs once per frame after the scene simulation step — use it when emitting from a context where listeners must not mutate the scene mid-traversal (e.g. inside a physics callback or another signal's emit).

    Type Parameters

    • A extends unknown[] = []
    Index

    Constructors

    Properties

    name: string

    Optional name, for debugging / error reporting.

    errorHandler: (error: unknown, signal: Signal<never[]>) => void = ...

    Called when a listener throws during emit. Replace to route listener errors elsewhere (or rethrow to make failures fatal, e.g. in tests). The default logs via console.error and continues, so one broken listener cannot starve the others.

    Accessors

    • get hasListeners(): boolean

      True if at least one listener is connected. Emitters can use this to skip building expensive emit arguments nobody will receive.

      Returns boolean

    Methods

    • Invoke every connected listener with args, synchronously and in connection order. See the class doc for reentrancy and error semantics.

      Parameters

      • ...args: A

      Returns void

    • Defer an emit until Signal.flushQueued — the engine flushes once per frame right after scene.update, so listeners run at a safe point where mutating the scene is allowed. Multiple queued emits (of any signal) run in queue order. Arguments are captured by reference at queue time.

      Outside an engine loop (unit tests, workers) call Signal.flushQueued yourself.

      Parameters

      • ...args: A

      Returns void

    • Run every pending queueEmit, including emits queued by the listeners themselves, until the queue is empty. The engine calls this once per frame after the simulation step. Guards against unbounded queue-from-flush loops by bailing out (with a console.error) after processing 10,000 entries in one flush.

      Returns void