platform-bible-utils
    Preparing search index...

    Class PlatformEventEmitter<T>

    Event manager - accepts subscriptions to an event and runs the subscription callbacks when the event is emitted Use eventEmitter.event(callback) to subscribe to the event. Use eventEmitter.emit(event) to run the subscriptions. Generally, this EventEmitter should be private, and its event should be public. That way, the emitter is not publicized, but anyone can subscribe to the event.

    Type Parameters

    • T

    Implements

    Index

    Constructors

    Properties

    subscribe: PlatformEvent<T> = ...

    Subscribes a function to run when this event is emitted.

    Function to run with the event when it is emitted

    Unsubscriber function to run to stop calling the passed-in function when the event is emitted

    Accessors

    Methods

    • Experimental

      Runs the subscriptions for the event, keeping each subscriber's failure to itself: a subscriber that throws hands its error to handleSubscriberError and the remaining subscribers still run.

      Use this where the emit is the only time subscribers are told about something that has already happened and will not be reported again — one broken subscriber must not cost the rest the news. Prefer emit everywhere else: a caller that can still act on a throw should see it.

      This does not await async subscribers. It routes their rejections — a subscriber whose promise rejects reaches handleSubscriberError the same way a synchronous throw does — but it does not sequence them: this returns as soon as every subscriber has been started, with any async subscriber still suspended at its first await. An emitter that tears something down right after emitting therefore tears it down out from under those subscribers.

      Parameters

      • event: T

        Event data to provide to subscribed callbacks

      • handleSubscriberError: (error: unknown, subscriberIndex: number) => void

        Run with the error a subscriber threw and that subscriber's position in the subscription order. Must not throw; a throw from it stops the remaining subscribers, which is the very thing this is here to prevent.

      Returns void

    • Experimental

      Function that runs the subscriptions for the event in isolation from each other. Added here so children can override emitIsolated and still call the base functionality.

      Parameters

      • event: T
      • handleSubscriberError: (error: unknown, subscriberIndex: number) => void

      Returns void