@clickup/ent-framework
Version:
A PostgreSQL graph-database-alike library with microsharding and row-level security
35 lines • 1.46 kB
TypeScript
export interface WeakTickerTarget {
onTick(tickNo: number, tickMs: number): "keep" | "unschedule";
}
/**
* A perf efficient approximate scheduler which doesn't retain the scheduled
* objects in memory, so they remain subject for GC.
*/
export declare class WeakTicker {
private slots;
/**
* Schedules a call to target.onTick() to be called periodically, every tickMs
* approximately.
* - The target scheduled will NOT be retained from GC. This is the main
* difference with setInterval() and the reason why we accept an object, not
* a closure.
* - The 1st call to target.onTick() will happen between 0 and tickMs from
* now: this is the second difference from setInterval(). Then, next calls
* will follow. The current tick number is passed to onTick().
* - If the same target is scheduled again, its tick number will be reset to
* 0, as if it's scheduled the very 1st time. The 2nd scheduling is cheap
* (just 2 map lookups), so an object can be rescheduled-over as many times
* as needed.
* - If target.onTick() returns "unschedule", the target will be unscheduled.
*/
schedule(target: WeakTickerTarget, tickMs: number): void;
/**
* Returns true if there are no targets scheduled at the moment.
*/
isEmpty(): boolean;
/**
* Called by internal setInterval().
*/
private onTick;
}
//# sourceMappingURL=WeakTicker.d.ts.map