Class Signal<T>

A Signal is an object that is used to dispatch and receive arbitrary events.

Type Parameters

  • T extends unknown[] | unknown = void

Properties

disconnectAllRequested: boolean = false

This flag is to safely handle DisconnectAll while firing. When enabled we stop looping callbacks for the current Fire.

queuedConnections: Map<number, CallbackItem<T>[]> = ...

Map from priority to all callbacks queued at that priority. Holds connections that were registered while this signal was firing (to be added after fire completes).

Methods

  • Connect a callback function to the signal.

    The returned function can be called to disconnect the callback.

    Parameters

    • callback: SignalCallback<T>

    Returns (() => void)

      • (): void
      • Returns void

  • Connect a callback function to the signal. Highest SignalPriority is called first.

    The returned function can be called to disconnect the callback.

    Parameters

    • priority: SignalPriority
    • callback: SignalCallback<T>

    Returns (() => void)

      • (): void
      • Returns void

  • Alias for DisconnectAll().

    Returns void

  • Clears all connections.

    Returns void

  • Invokes all callback functions with the given arguments.

    Parameters

    • Rest ...args: Parameters<[T] extends [unknown[]]
          ? ((...args) => never)
          : [T] extends [unknown]
              ? ((arg) => never)
              : (() => never)>

    Returns T

  • Returns the number of connections.

    Returns number

  • Returns true if there are any connections.

    Returns boolean

  • Connects a callback function to the signal. The connection is automatically disconnected after the first invocation.

    The returned function can be called to disconnect the callback.

    Parameters

    • callback: SignalCallback<T>

    Returns (() => void)

      • (): void
      • Returns void

  • Fires the given signal any time this signal is fired.

    The returned function can be called to disconnect the proxy.

    Parameters

    Returns (() => void)

      • (): void
      • Returns void

  • Register all queued connections during fire

    Returns void

  • Yields the current thread until the next invocation of the signal occurs. The invoked arguments will be returned.

    Returns SignalWait<T>

  • A yieldable signal is one in which calling Fire() may yield if any connected function handlers yield. This also means that all events will run in series. The default behavior is false, where the signal will call event handlers in separate threads, thus calling Fire() will not yield by default.

    Note: When using Cancellable events and not allowing Fire() to yield, then any connected handlers that do yield will throw a warning.

    // Example:
    const signal = new Signal().WithAllowYield(true);

    Parameters

    • value: boolean

    Returns Signal<T>