summaryrefslogtreecommitdiff
path: root/cli/js/workers.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cli/js/workers.ts')
-rw-r--r--cli/js/workers.ts19
1 files changed, 16 insertions, 3 deletions
diff --git a/cli/js/workers.ts b/cli/js/workers.ts
index 60ef73da0..2a5d4d190 100644
--- a/cli/js/workers.ts
+++ b/cli/js/workers.ts
@@ -27,12 +27,14 @@ function decodeMessage(dataIntArray: Uint8Array): any {
function createWorker(
specifier: string,
hasSourceCode: boolean,
- sourceCode: Uint8Array
+ sourceCode: Uint8Array,
+ name?: string
): { id: number; loaded: boolean } {
return sendSync(dispatch.OP_CREATE_WORKER, {
specifier,
hasSourceCode,
- sourceCode: new TextDecoder().decode(sourceCode)
+ sourceCode: new TextDecoder().decode(sourceCode),
+ name
});
}
@@ -72,10 +74,12 @@ export interface Worker {
onmessage?: (e: { data: any }) => void;
onmessageerror?: () => void;
postMessage(data: any): void;
+ terminate(): void;
}
export interface WorkerOptions {
type?: "classic" | "module";
+ name?: string;
}
export class WorkerImpl extends EventTarget implements Worker {
@@ -121,7 +125,12 @@ export class WorkerImpl extends EventTarget implements Worker {
}
*/
- const { id, loaded } = createWorker(specifier, hasSourceCode, sourceCode);
+ const { id, loaded } = createWorker(
+ specifier,
+ hasSourceCode,
+ sourceCode,
+ options?.name
+ );
this.id = id;
this.ready = loaded;
this.poll();
@@ -196,6 +205,10 @@ export class WorkerImpl extends EventTarget implements Worker {
hostPostMessage(this.id, data);
}
+ terminate(): void {
+ throw new Error("Not yet implemented");
+ }
+
private async run(): Promise<void> {
while (!this.isClosing) {
const data = await hostGetMessage(this.id);