Publish–subscribe pattern implementation that guarantees the delivery of published messages even if any of listeners would throw an error.

Type Parameters

  • T = void

    The published message.

Constructors

Accessors

  • get listenerCount(): number
  • The number of subscribed listeners.

    Returns number

Methods

  • Synchronously invokes listeners with the published message.

    Parameters

    • message: T

      The published message.

    Returns void

  • Adds a listener that would receive all messages published via publish.

    Parameters

    • listener: ((message) => any)

      The callback.

        • (message): any
        • Parameters

          • message: T

          Returns any

    Returns (() => void)

    The callback that unsubscribes the listener.

      • (): void
      • Returns void

  • Returns void

  • Waits for a message that satisfies the given predicate to be published and resolves with that message.

    Type Parameters

    • R

      A subtype of T that the predicate function identifies as satisfying the condition.

    Parameters

    • predicate: ((message) => message is R)

      A function that takes the message as a parameter and returns true if the message satisfies the condition, otherwise false.

        • (message): message is R
        • Parameters

          • message: T

          Returns message is R

    Returns AbortablePromise<R>

    An AbortablePromise that resolves with the published message that satisfies the predicate.

  • Waits for a message that satisfies the given predicate to be published and resolves with that message.

    Parameters

    • predicate: ((message) => boolean)

      A function that takes the message as a parameter and returns true if the message satisfies the condition, otherwise false.

        • (message): boolean
        • Parameters

          • message: T

          Returns boolean

    Returns AbortablePromise<T>

    An AbortablePromise that resolves with the published message that satisfies the predicate.