MCPcopy Create free account
hub / github.com/ether/etherpad / createSchedulerRunner

Function createSchedulerRunner

src/node/updater/Scheduler.ts:173–198  ·  view source on GitHub ↗
({
  now, setTimer, clearTimer, triggerApply,
}: SchedulerRunnerDeps)

Source from the content-addressed store, hash-verified

171}
172
173export const createSchedulerRunner = ({
174 now, setTimer, clearTimer, triggerApply,
175}: SchedulerRunnerDeps): SchedulerRunner => {
176 let timer: NodeJS.Timeout | null = null;
177 let armedFor: string | null = null;
178
179 return {
180 arm: ({targetTag, scheduledFor}) => {
181 if (timer) { clearTimer(timer); timer = null; }
182 armedFor = targetTag;
183 const delay = Math.max(0, new Date(scheduledFor).getTime() - now().getTime());
184 timer = setTimer(() => {
185 timer = null;
186 const tag = armedFor;
187 armedFor = null;
188 if (!tag) return;
189 // Discard promise — apply pipeline owns its own error reporting.
190 void triggerApply(tag);
191 }, delay);
192 },
193 cancel: () => {
194 if (timer) { clearTimer(timer); timer = null; }
195 armedFor = null;
196 },
197 };
198};

Callers 3

Scheduler.test.tsFile · 0.90
expressCreateServerFunction · 0.90

Calls 1

nowFunction · 0.85

Tested by

no test coverage detected