MCPcopy Index your code
hub / github.com/sourcebot-dev/sourcebot / setIntervalAsync

Function setIntervalAsync

packages/backend/src/utils.ts:267–287  ·  view source on GitHub ↗
(target: () => Promise<void>, pollingIntervalMs: number)

Source from the content-addressed store, hash-verified

265// setInterval wrapper that ensures async callbacks are not executed concurrently.
266// @see: https://mottaquikarim.github.io/dev/posts/setinterval-that-blocks-on-await/
267export const setIntervalAsync = (target: () => Promise<void>, pollingIntervalMs: number): NodeJS.Timeout => {
268 const setIntervalWithPromise = <T extends (...args: any[]) => Promise<any>>(
269 target: T
270 ): (...args: Parameters<T>) => Promise<void> => {
271 return async function (...args: Parameters<T>): Promise<void> {
272 if ((target as any).isRunning) return;
273
274 (target as any).isRunning = true;
275 try {
276 await target(...args);
277 } finally {
278 (target as any).isRunning = false;
279 }
280 };
281 }
282
283 return setInterval(
284 setIntervalWithPromise(target),
285 pollingIntervalMs
286 );
287}

Callers 5

startSchedulerMethod · 0.85
startSchedulerMethod · 0.85
startSchedulerMethod · 0.85
startSchedulerMethod · 0.85
startSchedulerMethod · 0.85

Calls 1

setIntervalWithPromiseFunction · 0.85

Tested by

no test coverage detected