import { IdleState } from '../core'; import { Poller } from './poller'; /** * Factory for creating pollers. * * @example Create a poller * ```ts * import { PlatformServiceName } from '@limetech/lime-web-components'; * * interface DealSummary { * open: number; * won: number; * } * * const factory = platform.get(PlatformServiceName.PollerFactory); * const http = platform.get(PlatformServiceName.Http); * * const summaryPoller = factory.create( * (): Promise => http.get('my_addon/deal_summary'), * 60_000 * ); * * // Only polls while the user is idle, so it does not compete with their work * const prefetchPoller = factory.createIdlePoller( * (): Promise => http.get('my_addon/prefetch'), * 300_000, * 'idle' * ); * ``` * * @beta * @group Poller */ export interface PollerFactory { /** * Creates a generic poller * * @param callback - An asynchronous function that will be executed * periodically by the poller. * @param intervalMs - The interval, in milliseconds, at which the callback * should be executed. * @returns the poller */ create(callback: () => Promise, intervalMs: number): Poller; /** * Creates a poller that executes its callback based on the users idle * status * * @param callback - An asynchronous function that will be executed * periodically by the poller based on the users idle status. * @param intervalMs - The interval, in milliseconds, at which the callback * should be executed. * @param 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 the poller */ createIdlePoller(callback: () => Promise, intervalMs: number, idleState?: IdleState): Poller; }