Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Poll<T, U, V>

A class that wraps an asynchronous function to poll at a regular interval with exponential increases to the interval length if the poll fails. A namespace for Poll types, interfaces, and statics.

Type parameters

  • T

    The resolved type of the factory's promises. Defaults to any.

  • U

    The rejected type of the factory's promises. Defaults to any.

  • V: string

    An optional type to extend the phases supported by a poll. Defaults to standby, which already exists in the Phase type.

Hierarchy

  • Poll

Implements

  • IObservableDisposable
  • IPoll<T, U, V>

Index

Type aliases

Static Factory

Factory<T, U, V>: function

A promise factory that returns an individual poll request.

Type parameters

  • T

    The resolved type of the factory's promises.

  • U

    The rejected type of the factory's promises.

  • V: string

    The type to extend the phases supported by a poll.

Type declaration

    • (state: State<T, U, V>): Promise<T>
    • Parameters

      Returns Promise<T>

Static Standby

Standby: "never" | "when-hidden"

Indicates when the poll switches to standby.

Constructors

constructor

  • Instantiate a new poll with exponential backoff in case of failure.

    Parameters

    • options: IOptions<T, U, V>

      The poll instantiation options.

    Returns Poll

Properties

Private _disposed

_disposed: Signal<this, void> = new Signal<this, void>(this)

Private _factory

_factory: Factory<T, U, V>

Private _frequency

_frequency: Frequency

Private _standby

_standby: Standby | function

Private _state

_state: State<T, U, V>

Private _tick

_tick: PromiseDelegate<this> = new PromiseDelegate<this>()

Private _ticked

_ticked: Signal<this, object> = new Signal<this, IPoll.State<T, U, V>>(this)

Private _timeout

_timeout: any = -1

name

name: string

The name of the poll.

Static IMMEDIATE

IMMEDIATE: 0 = 0

An interval value that indicates the poll should tick immediately.

Static MAX_INTERVAL

MAX_INTERVAL: 2147483647 = 2147483647

Delays are 32-bit integers in many browsers so intervals need to be capped.

Notes

https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout#Maximum_delay_value

Static NEVER

NEVER: number = Infinity

An interval value that indicates the poll should never tick.

Accessors

disposed

  • get disposed(): ISignal<this, void>

frequency

isDisposed

  • get isDisposed(): boolean

standby

  • get standby(): Standby | function
  • set standby(standby: Standby | function): void

state

  • get state(): State<T, U, V>

tick

  • get tick(): Promise<this>

ticked

  • get ticked(): ISignal<this, State<T, U, V>>
  • A signal emitted when the poll ticks and fires off a new request.

    Returns ISignal<this, State<T, U, V>>

Methods

Private _execute

  • _execute(): void

dispose

  • dispose(): void

refresh

  • refresh(): Promise<void>
  • Refreshes the poll. Schedules refreshed tick if necessary.

    Returns Promise<void>

    A promise that resolves after tick is scheduled and never rejects.

    Notes

    The returned promise resolves after the tick is scheduled, but before the polling action is run. To wait until after the poll action executes, await the poll.tick promise: await poll.refresh(); await poll.tick;

schedule

  • schedule(next?: Partial<State<T, U, V> & object>): Promise<void>
  • Schedule the next poll tick.

    Parameters

    • Default value next: Partial<State<T, U, V> & object> = {}

      The next poll state data to schedule. Defaults to standby.

    Returns Promise<void>

    A promise that resolves when the next poll state is active.

    Notes

    This method is not meant to be invoked by user code typically. It is public to allow poll instances to be composed into classes that schedule ticks.

start

  • start(): Promise<void>
  • Starts the poll. Schedules started tick if necessary.

    Returns Promise<void>

    A promise that resolves after tick is scheduled and never rejects.

stop

  • stop(): Promise<void>
  • Stops the poll. Schedules stopped tick if necessary.

    Returns Promise<void>

    A promise that resolves after tick is scheduled and never rejects.

Generated using TypeDoc