AngularTS
    Preparing search index...

    Class EventBus

    Application-wide asynchronous publish/subscribe utility.

    EventBus powers $eventBus for cross-boundary domain events, browser callbacks, worker messages, realtime messages, and non-Angular integrations. It is intentionally not a state store and should not replace scope events for parent/child scope-tree communication.

    Index

    Constructors

    • Create a publish/subscribe event bus.

      Applications usually receive the singleton instance by injecting $eventBus instead of constructing this class directly.

      Parameters

      Returns EventBus

    Methods

    • Dispose the instance, removing all topics and listeners.

      Returns void

    • Get the number of subscribers for a topic.

      This is the public diagnostic surface for $eventBus. It reports active registered listeners only; topic listings, leak reports, and reactive diagnostics are intentionally not exposed.

      Parameters

      • topic: string

        Topic name to inspect.

      Returns number

      The number of currently registered listeners.

    • Checks if instance has been disposed.

      Returns boolean

      True if disposed.

    • Publish a value to a topic asynchronously.

      Listeners are invoked in the order they were added until delivery finishes or $exceptionHandler terminates the publication. Delivery is scheduled with queueMicrotask. Scope-owned listeners are skipped if their scope is destroyed before the queued delivery runs.

      Parameters

      • topic: string

        The topic to publish.

      • ...args: unknown[]

        Arguments to pass to listeners.

      Returns boolean

      True if any listeners exist for this topic.

    • Reset the bus to its initial state without disposing it.

      All topics and listeners are removed, and the instance can be reused.

      Returns void

    • Replace the runtime delivery policy used by future publications.

      The default policy delivers every active listener. Configured policies can drop deliveries for specific topics, scopes, or application metadata.

      Parameters

      Returns void

    • Subscribe a function to a topic.

      The returned function removes only this listener registration. When context is provided, it becomes the listener this binding. When context is an AngularTS scope proxy, the scope also owns the listener lifecycle: destroying the scope removes the listener and prevents queued delivery from reaching the destroyed scope.

      Parameters

      • topic: string

        The topic to subscribe to.

      • fn: EventBusListener

        The callback function to invoke when published.

      Returns () => boolean

      A function that unsubscribes this listener.

    • Subscribe a function to a topic.

      The returned function removes only this listener registration. When context is provided, it becomes the listener this binding. When context is an AngularTS scope proxy, the scope also owns the listener lifecycle: destroying the scope removes the listener and prevents queued delivery from reaching the destroyed scope.

      Type Parameters

      • TContext

      Parameters

      Returns () => boolean

      A function that unsubscribes this listener.

    • Subscribe a function to a topic only once.

      Listener is removed before the first invocation. When context is provided, it becomes the listener this binding. When context is an AngularTS scope proxy, scope destruction before first delivery removes the one-time listener.

      Parameters

      • topic: string

        The topic to subscribe to.

      • fn: EventBusListener

        The callback function.

      Returns () => boolean

      A function that unsubscribes this listener.

    • Subscribe a function to a topic only once.

      Listener is removed before the first invocation. When context is provided, it becomes the listener this binding. When context is an AngularTS scope proxy, scope destruction before first delivery removes the one-time listener.

      Type Parameters

      • TContext

      Parameters

      Returns () => boolean

      A function that unsubscribes this listener.

    • Unsubscribe a specific function from a topic. Matches by function reference and optional context.

      Parameters

      • topic: string

        The topic to unsubscribe from.

      • fn: EventBusListener

        The listener function.

      Returns boolean

      True if the listener was found and removed.

    • Unsubscribe a specific function from a topic. Matches by function reference and optional context.

      Type Parameters

      • TContext

      Parameters

      Returns boolean

      True if the listener was found and removed.