Class IntervalEmitter

An emitter that repeatedly emits events with a fixed time delay between each event

Hierarchy (view full)

Constructors

Properties

interval?: number
ms: number

Delay in milliseconds.

started: boolean = true

Whether the interval starts immediately.

Accessors

  • get observed(): boolean
  • Returns boolean

    True if this emitter has any observers, false otherwise.

Methods

  • Filter events emitted by this emitter.

    Parameters

    • f: ((event) => boolean)

      The predicate to apply to each event.

        • (event): boolean
        • Parameters

          • event: void

          Returns boolean

    Returns Emitter<void>

    An emitter than only emits events emitted by this emitter for which f returns true.

  • Creates an emitter that counts events emitted by this emitter.

    Returns Emitter<number>

    An emitter that emits the index, starting at zero, of every event emitted by this emitter.

  • Apply a function to all events and their index (starting at zero) emitted by this emitter.

    Type Parameters

    • TOut

    Parameters

    • f: ((event, index) => TOut)
        • (event, index): TOut
        • Parameters

          • event: void
          • index: number

          Returns TOut

    Returns Emitter<TOut>

    An emitter that applies the function f to all events emitted by this emitter.

  • Apply a function to all events emitted by this emitter.

    Type Parameters

    • TOut

    Parameters

    • f: ((event) => TOut)

      The function to apply to events.

        • (event): TOut
        • Parameters

          • event: void

          Returns TOut

    Returns Emitter<TOut>

    An emitter that applies the function f to all events emitted by this emitter.

  • Create a promise that resolves the next time an event is emitted by this emitter.

    Returns Promise<void>

    A promise that resolves to the next event emitted by this emitter.

  • Attach an observer.

    Parameters

    • observer: Observer<void>

      The observer function to attach.

    Returns (() => void)

    A function that can be called to detach the observer. Alternatively unobserve can be called.

      • (): void
      • Returns void

  • Start the interval if not already started. If there aren't currently any observers the interval won't start until observed.

    Returns void