From 161adfc51b750a7c8c62a898ea9948c2ad5b6cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 29 Jan 2020 18:54:23 +0100 Subject: workers: proper TS libs, more spec-compliant APIs (#3812) * split lib.deno_main.d.ts into: - lib.deno.shared_globals.d.ts - lib.deno.window.d.ts - lib.deno.worker.d.ts * remove no longer used libs: - lib.deno_main.d.ts - lib.deno_worker.d.ts * change module loading to use proper TS library for compilation * align to Worker API spec: - Worker.terminate() - self.close() - self.name --- cli/js/workers.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'cli/js/workers.ts') 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 { while (!this.isClosing) { const data = await hostGetMessage(this.id); -- cgit v1.2.3