Bulk run
This commit is contained in:
@@ -18,7 +18,51 @@ export async function startScript(
|
||||
worker.terminate();
|
||||
}
|
||||
|
||||
worker = new Worker(new URL("./worker.ts", import.meta.url));
|
||||
worker = new Worker(new URL("./worker_human.ts", import.meta.url));
|
||||
|
||||
worker.onmessage = (event) => {
|
||||
const { type, line, error } = event.data;
|
||||
|
||||
if (type === "output") {
|
||||
appendOutput(line);
|
||||
} else if (type === "terminal") {
|
||||
appendTerminal(line);
|
||||
} else if (type === "complete") {
|
||||
worker?.terminate();
|
||||
worker = null;
|
||||
resolve();
|
||||
} else if (type === "error") {
|
||||
worker?.terminate();
|
||||
worker = null;
|
||||
reject(new Error(error));
|
||||
} else if (type === "stopped") {
|
||||
worker?.terminate();
|
||||
worker = null;
|
||||
resolve();
|
||||
}
|
||||
};
|
||||
|
||||
worker.onerror = (error) => {
|
||||
worker?.terminate();
|
||||
worker = null;
|
||||
reject(error);
|
||||
};
|
||||
|
||||
worker.postMessage({ type: "run", script });
|
||||
});
|
||||
}
|
||||
|
||||
export async function startScriptBulk(
|
||||
script: string,
|
||||
appendOutput: (line: string) => void,
|
||||
appendTerminal: (line: string) => void
|
||||
): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (worker) {
|
||||
worker.terminate();
|
||||
}
|
||||
|
||||
worker = new Worker(new URL("./worker_bulk.ts", import.meta.url));
|
||||
|
||||
worker.onmessage = (event) => {
|
||||
const { type, line, error } = event.data;
|
||||
|
||||
Reference in New Issue
Block a user