Wait for background workers before finish notices and cancel tools on shutdown
This commit is contained in:
+19
-1
@@ -68776,13 +68776,23 @@ function environment(cwd = "/", conversation, invocation) {
|
||||
if (!appended.ok) throw new Error(appended.error.message);
|
||||
}
|
||||
};
|
||||
let rid;
|
||||
const abort = () => {
|
||||
if (rid !== void 0) {
|
||||
Deno.core.close(rid);
|
||||
rid = void 0;
|
||||
}
|
||||
};
|
||||
try {
|
||||
const rid = ops.op_exec(command, options?.cwd ?? cwd, options?.timeout, void 0, void 0, conversations, tag);
|
||||
context.abortSignal?.throwIfAborted();
|
||||
rid = ops.op_exec(command, options?.cwd ?? cwd, options?.timeout, void 0, void 0, conversations, tag);
|
||||
context.abortSignal?.addEventListener("abort", abort, { once: true });
|
||||
const decoders = { stdout: new TextDecoder(), stderr: new TextDecoder() };
|
||||
let result;
|
||||
while (true) {
|
||||
const chunk = await ops.op_exec_next(rid);
|
||||
if (!chunk.stream) {
|
||||
rid = void 0;
|
||||
result = chunk;
|
||||
break;
|
||||
}
|
||||
@@ -68796,6 +68806,9 @@ function environment(cwd = "/", conversation, invocation) {
|
||||
return ok({ exitCode: result.exitCode, ...spillPath ? { spillPath } : {} });
|
||||
} catch (error) {
|
||||
return { ok: false, error: Object.assign(new Error(String(error)), { code: "unknown", ...spillPath ? { spillPath } : {} }) };
|
||||
} finally {
|
||||
context.abortSignal?.removeEventListener("abort", abort);
|
||||
abort();
|
||||
}
|
||||
},
|
||||
cleanup: async () => {
|
||||
@@ -69812,6 +69825,11 @@ async function serve(harness2, context, afterSubmit, api2) {
|
||||
};
|
||||
while (true) {
|
||||
const input = await Deno.core.ops.op_input();
|
||||
if (input?.type === "shutdown") {
|
||||
await harness2.close(context);
|
||||
await Promise.all(pending);
|
||||
return;
|
||||
}
|
||||
if (input === null || input.type === "stop") {
|
||||
await harness2.waitForIdle(context);
|
||||
await Promise.all(pending);
|
||||
|
||||
Reference in New Issue
Block a user