diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-01-29 18:54:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-29 18:54:23 +0100 |
commit | 161adfc51b750a7c8c62a898ea9948c2ad5b6cd9 (patch) | |
tree | 6d53db2a4acd30207372f665a3ba463e26db6fcf /cli/js/workers.ts | |
parent | d14864c57cebbd1d5bc18b8a9e05e522eb9987b0 (diff) |
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
Diffstat (limited to 'cli/js/workers.ts')
-rw-r--r-- | cli/js/workers.ts | 19 |
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); |