mirror of
https://github.com/denoland/deno.git
synced 2024-11-01 09:24:20 -04:00
79b3bc05d6
* establish basic event loop for workers * make "self.close()" inside worker * remove "runWorkerMessageLoop() - instead manually call global function in Rust when message arrives. This is done in preparation for structured clone * refactor "WorkerChannel" and use distinct structs for internal and external channels; "WorkerChannelsInternal" and "WorkerHandle" * move "State.worker_channels_internal" to "Worker.internal_channels" * add "WorkerEvent" enum for child->host communication; currently "Message(Buf)" and "Error(ErrBox)" variants are supported * add tests for nested workers * add tests for worker throwing error on startup
22 lines
389 B
JavaScript
22 lines
389 B
JavaScript
let thrown = false;
|
|
|
|
if (self.name !== "jsWorker") {
|
|
throw Error(`Bad worker name: ${self.name}, expected jsWorker`);
|
|
}
|
|
|
|
onmessage = function(e) {
|
|
console.log(e.data);
|
|
|
|
if (thrown === false) {
|
|
thrown = true;
|
|
throw new SyntaxError("[test error]");
|
|
}
|
|
|
|
postMessage(e.data);
|
|
close();
|
|
};
|
|
|
|
onerror = function() {
|
|
console.log("called onerror in worker");
|
|
return false;
|
|
};
|