Options
All
  • Public
  • Public/Protected
  • All
Menu
class

Implements subscribing to events and triggering them.

Type parameters

  • T

Hierarchy

Index

Constructors

constructor

Properties

Protected _subs

_subs: ISubscriber<T>[] = []

Internal list of subscribers.

max

max: number

Maximum number of subscribers that can receive data. 0 = no limit applies.

Static Protected _nextCall

_nextCall: nextTick = typeof process === 'undefined' ? setTimeout : process.nextTick

For compatibility with web browsers.

Accessors

count

count:

Current number of subscribers.

Methods

Protected _createUnsub

  • _createUnsub(sub: ISubscriber<T>): function
  • Creates unsubscribe callback function for the Subscription class.

    Parameters

    • sub: ISubscriber<T>

      Subscriber details.

    Returns function

    Function that implements the unsubscribe request.

      • (): void
      • Returns void

Protected _getRecipients

  • _getRecipients(): ISubscriber<T>[]
  • Gets all recipients that must receive data.

    It returns a copy of subscribers array for safe iteration, while applying the maximum limit when it is set with the max option.

    Returns ISubscriber<T>[]

Protected _removeSub

  • _removeSub(sub: ISubscriber<T>): void
  • Removes an existing subscriber from the list.

    Parameters

    • sub: ISubscriber<T>

      Subscriber to be removed, which must be on the list.

    Returns void

next

  • next(data: T, cb?: function): number
  • Asynchronous data broadcast to all subscribers.

    Parameters

    • data: T

      Data to be sent, according to the type template.

    • Optional cb: function

      Optional callback function to be notified when the last recipient has received the data. The function takes one parameter - total number of clients that received the data. Note that asynchronous subscribers may still be processing the data at this point.

        • (count: number): void
        • Parameters

          • count: number

          Returns void

    Returns number

    Number of clients that will be receiving the data.

nextSafe

  • nextSafe(data: T, onError: function): number
  • Safe asynchronous data broadcast to all subscribers.

    Errors from subscription callbacks are passed into the callback function, which handles both synchronous and asynchronous subscription functions.

    Parameters

    • data: T

      Data to be sent, according to the type template.

    • onError: function

      Callback for handling errors from subscribers.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns number

    Number of clients that will be receiving the data.

nextSync

  • nextSync(data: T): number
  • Synchronous data broadcast to all subscribers.

    Parameters

    • data: T

      Data to be sent, according to the type template.

    Returns number

    Number of clients that have received the data.

    Note that asynchronous subscribers may still be processing the data.

subscribe

  • Subscribes to receive all data events.

    Parameters

    • cb: SubFunction<T>

      Data notification callback function.

    Returns Subscription

    Object for unsubscribing safely.

unsubscribeAll

  • unsubscribeAll(): void

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc