MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / drainJobs

Function drainJobs

packages/kernel/runtime-quickjs/src/index.ts:367–386  ·  view source on GitHub ↗
(
  context: QuickJSContext,
  runtime: QuickJSRuntime,
  deadline: DeadlineTracker,
  timeoutMs: number,
)

Source from the content-addressed store, hash-verified

365 });
366
367const drainJobs = (
368 context: QuickJSContext,
369 runtime: QuickJSRuntime,
370 deadline: DeadlineTracker,
371 timeoutMs: number,
372): void => {
373 while (runtime.hasPendingJob()) {
374 const deadlineMs = deadline.deadlineMs();
375 if (deadlineMs !== null && Date.now() >= deadlineMs) {
376 throw new Error(timeoutMessage(timeoutMs));
377 }
378
379 const pending = runtime.executePendingJobs();
380 if (pending.error) {
381 const error = context.dump(pending.error);
382 pending.error.dispose();
383 throw toError(error);
384 }
385 }
386};
387
388const waitForDeferreds = async (
389 pendingDeferreds: ReadonlySet<QuickJSDeferredPromise>,

Callers 1

drainAsyncFunction · 0.85

Calls 3

timeoutMessageFunction · 0.85
disposeMethod · 0.80
toErrorFunction · 0.70

Tested by

no test coverage detected