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

Function drainJobs

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

Source from the content-addressed store, hash-verified

345 });
346
347const drainJobs = (
348 context: QuickJSContext,
349 runtime: QuickJSRuntime,
350 deadline: DeadlineTracker,
351 timeoutMs: number,
352): void => {
353 while (runtime.hasPendingJob()) {
354 const deadlineMs = deadline.deadlineMs();
355 if (deadlineMs !== null && Date.now() >= deadlineMs) {
356 throw new Error(timeoutMessage(timeoutMs));
357 }
358
359 const pending = runtime.executePendingJobs();
360 if (pending.error) {
361 const error = context.dump(pending.error);
362 pending.error.dispose();
363 throw toError(error);
364 }
365 }
366};
367
368const waitForDeferreds = async (
369 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