Factory for creating pollers.

Example

const poller = factory.create(
async () => fetchDataFromAPI(),
60000 // Polling every 1 minute
);

const unsubscribe = poller.subscribe((data) => {
console.log('Received data:', data);
});

unsubscribe();

Hierarchy

  • PollerFactory

Methods

  • Creates a generic poller

    Returns

    the poller

    Type Parameters

    • T

    Parameters

    • callback: (() => Promise<T>)

      An asynchronous function that will be executed periodically by the poller.

        • (): Promise<T>
        • Returns Promise<T>

    • intervalMs: number

      The interval, in milliseconds, at which the callback should be executed.

    Returns Poller<T>

  • Creates a poller that executes its callback based on the users idle status

    Returns

    the poller

    Type Parameters

    • T

    Parameters

    • callback: (() => Promise<T>)

      An asynchronous function that will be executed periodically by the poller based on the users idle status.

        • (): Promise<T>
        • Returns Promise<T>

    • intervalMs: number

      The interval, in milliseconds, at which the callback should be executed.

    • Optional idleState: IdleState

      The idle state when the poller is active. When set to active, the poller will only execute while the user is actively using the application. When set to idle, the poller will only execute while the user is idle. Default value is active.

    Returns Poller<T>