mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
fix(ext/node): emit online
event after worker thread is initialized (#25243)
Fixes #23281. Part of #20613. We were emitting the `online` event in the constructor, so the caller could never receive it (since there was no time for them to add a listener). Instead, emit the event where it's intended – after the worker is initialized. --- After this parcel no longer freezes, but still will fail due to other bugs (which will be fixed in other PRs)
This commit is contained in:
parent
3dba98532a
commit
511d13abaf
2 changed files with 65 additions and 3 deletions
|
@ -590,3 +590,34 @@ Deno.test({
|
|||
channel.port2.close();
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "[node/worker_threads] Emits online event",
|
||||
async fn() {
|
||||
const worker = new workerThreads.Worker(
|
||||
`
|
||||
import { parentPort } from "node:worker_threads";
|
||||
const p = Promise.withResolvers();
|
||||
let ok = false;
|
||||
parentPort.on("message", () => {
|
||||
ok = true;
|
||||
p.resolve();
|
||||
});
|
||||
await Promise.race([p.promise, new Promise(resolve => setTimeout(resolve, 20000))]);
|
||||
if (ok) {
|
||||
parentPort.postMessage("ok");
|
||||
} else {
|
||||
parentPort.postMessage("timed out");
|
||||
}
|
||||
`,
|
||||
{
|
||||
eval: true,
|
||||
},
|
||||
);
|
||||
worker.on("online", () => {
|
||||
worker.postMessage("ok");
|
||||
});
|
||||
assertEquals((await once(worker, "message"))[0], "ok");
|
||||
worker.terminate();
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue