Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Publisher<T>

Type parameters

  • T

Hierarchy

  • Publisher

Index

Constructors

Properties

Methods

Constructors

constructor

  • new Publisher(initialPublish?: T): Publisher
  • const publisher = new Publisher();
    

    Parameters

    • Optional initialPublish: T

      You can post your first publication, but no one will see it

    Returns Publisher

Properties

Private eventEmitter

eventEmitter: EventEmitter = new EventEmitter()

Private subscribers

subscribers: Map<string, Subscriber<T>> = new Map()

Methods

Private emit

  • emit<K>(eventName: K, ...args: PublisherEvents<T>[K]): void

on

  • on<K>(eventName: K, listener: (...args: PublisherEvents<T>[K]) => Awaitable<void>): void
  • Type parameters

    Parameters

    • eventName: K
    • listener: (...args: PublisherEvents<T>[K]) => Awaitable<void>
        • (...args: PublisherEvents<T>[K]): Awaitable<void>
        • Parameters

          • Rest ...args: PublisherEvents<T>[K]

          Returns Awaitable<void>

    Returns void

publish

  • publish(data: T): void
  • ```js const publisher = new Publisher();

    publisher.subscribe((data) => { console.log(data); });

    publisher.publish(5);

    // Output: 5 ```

    Parameters

    • data: T

    Returns void

subscribe

Generated using TypeDoc