UNPKG

@adaptabletools/adaptable

Version:

Powerful AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements

28 lines (27 loc) 837 B
import { getNextRunDateFromSchedule } from './ScheduleHelper'; const dateTimeouts = {}; export const ScheduleJobRunner = { scheduleJob(date, fn, onFire) { const timestamp = +date; const now = Date.now(); const timeUntilDate = timestamp - now; if (timeUntilDate > 0) { const timeoutId = +setTimeout(() => { fn(); onFire?.(); }, timeUntilDate); dateTimeouts[timestamp] = timeoutId; } return { cancel: () => { const theTimeout = dateTimeouts[timestamp]; if (theTimeout != undefined) { clearTimeout(theTimeout); } }, }; }, getNextRunDate(schedule) { return getNextRunDateFromSchedule(schedule); }, };