MCPcopy
hub / github.com/coder/mux / maybeStartQueuedTasks

Method maybeStartQueuedTasks

src/node/services/taskService.ts:6978–7009  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6976 }
6977
6978 async maybeStartQueuedTasks(): Promise<void> {
6979 const existingRun = this.maybeStartQueuedTasksInFlight;
6980 if (existingRun != null) {
6981 this.maybeStartQueuedTasksRerunRequested = true;
6982 await existingRun;
6983 return;
6984 }
6985
6986 // A foreground task waiter registers itself in waitForAgentReport's async setup. Yield once so
6987 // immediate scheduler calls from the same turn see that foreground-awaiting state and avoid a
6988 // nested-task deadlock at maxParallelAgentTasks=1.
6989 await Promise.resolve();
6990 const existingRunAfterYield = this.maybeStartQueuedTasksInFlight;
6991 if (existingRunAfterYield != null) {
6992 this.maybeStartQueuedTasksRerunRequested = true;
6993 await existingRunAfterYield;
6994 return;
6995 }
6996
6997 const run = (async () => {
6998 do {
6999 this.maybeStartQueuedTasksRerunRequested = false;
7000 await this.maybeStartQueuedTasksFromReservations();
7001 } while (this.maybeStartQueuedTasksRerunRequested);
7002 })().finally(() => {
7003 if (this.maybeStartQueuedTasksInFlight === run) {
7004 this.maybeStartQueuedTasksInFlight = undefined;
7005 }
7006 });
7007 this.maybeStartQueuedTasksInFlight = run;
7008 await run;
7009 }
7010
7011 private async maybeStartQueuedTasksFromReservations(): Promise<void> {
7012 const plans: TaskLaunchPlan[] = [];

Callers 9

initializeMethod · 0.95
createMethod · 0.95
routerFunction · 0.80

Calls 2

resolveMethod · 0.80

Tested by

no test coverage detected