nats-jobs
Version:
Background job processor using NATS
35 lines (34 loc) • 1.16 kB
TypeScript
import type { BackoffOptions, Deferred } from './types';
import type { JsMsg, Nanos } from 'nats';
export declare const nanos: (x: string) => number;
export declare const nanosToMs: (x: Nanos | undefined) => number;
/**
* Given a starting backoff in ms, generate an array of doubling
* values with at most `numEntries` and repeating after
* `repeatAfter` entries.
*
* Note that `repeatAfter` defaults to `numEntries` and `numEntries`
* defaults to 5.
*/
export declare const expBackoff: (startMs: number, options?: BackoffOptions) => number[];
export declare function defer<A>(): Deferred<A>;
/**
* Get the next backoff based on the redelivery count. If given
* an array and no item exists for the attempt number use the last
* backoff in the array.
*/
export declare const getNextBackoff: (backoff: number | number[], msg: JsMsg) => number | undefined;
/**
* Call fn on an interval.
*/
export declare const repeater: (fn: () => void, interval: number) => {
start: () => void;
stop: () => void;
};
/**
* Calculate elapsed time in milliseconds.
*/
export declare const stopwatch: () => {
start: () => void;
stop: () => number;
};