import { Logger } from './logger'; /** * Represent a running task that can be stopped * * Examples: A poller, a watcher. */ export interface RunningTask { /** Flag task to be stopped. Might not be inmediate */ stop(): void; /** Indicates wether the task is running */ isRunning(): boolean; } export interface TaskOptions { /** Name for the task. To be used in logging messages */ name: string; /** Logger function */ logger?: Logger; } interface RepeatTaskOptions extends TaskOptions { /** seconds between repetition */ timeInBetweenMS: number; /** initial delay for first run */ initialDelayMS?: number; } export interface RepeatTaskContext { /** Number of times the task has been executed (starts in 1) */ executionNumber: number; /** Flag task to be stopped. Might not be inmediate */ stopTask(): void; } /** * Runs an async function eternally until stopped * * @param fn function to run */ export declare function repeatTask(opts: RepeatTaskOptions, fn: (ctx: RepeatTaskContext) => Promise): RunningTask; export declare function conditionWatcher(opts: RepeatTaskOptions & { pollCondition: () => Promise; onSuccess: () => void | Promise; }): RunningTask; export interface RunningTaskWithValue extends RunningTask { onValue(): Promise; } export interface RetryTaskOptions extends TaskOptions { /** seconds between repetition */ timeInBetweenMS: number; /** Maximum number of attemps */ maxAttemps: number; /** Function that tries to obtain a value A or returns null */ tryGetValue: () => Promise; } export declare function tryObtainValueWithRetries(opts: RetryTaskOptions): RunningTaskWithValue; export {};