Networked version of EventEmitter - accepts subscriptions to an event and runs the subscription callbacks when the event is emitted. Events on NetworkEventEmitters can be emitted across processes. They are coordinated between processes by their type. 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.

WARNING: Do not use this class directly outside of NetworkService, or it will not do what you expect. Use NetworkService.createNetworkEventEmitter.

WARNING: You cannot emit events with complex types on the network.

Type Parameters

  • T

Hierarchy

  • PlatformEventEmitter<T>
    • default

Constructors

  • Creates a NetworkEventEmitter

    Type Parameters

    • T

    Parameters

    • networkSubscriber: PlatformEventHandler<T>

      Callback that accepts the event and emits it to other processes

    • networkDisposer: () => void

      Callback that unlinks this emitter from the network

    Returns default<T>

Properties

dispose: () => Promise<boolean>

Disposes of this event, preparing it to release from memory

emit: (event: T) => void

Runs the subscriptions for the event

Type declaration

    • (event: T): void
    • Parameters

      • event: T

        Event data to provide to subscribed callbacks

      Returns void

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

event

Accessors

  • get event(): PlatformEvent<T>

    Event for listeners to subscribe to. Subscribes a function to run when this event is emitted. Use like const unsubscriber = event(callback)

    Returns PlatformEvent<T>

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

Methods

  • Disposes of this event, preparing it to release from memory. Added here so children can override emit and still call the base functionality.

    Returns Promise<boolean>

  • Function that runs the subscriptions for the event. Added here so children can override emit and still call the base functionality. See NetworkEventEmitter.emit for example

    Parameters

    • event: T

    Returns void

  • Runs only the subscriptions for the event that are on this process. Does not send over network

    Parameters

    • event: T

      Event data to provide to subscribed callbacks

    Returns void