mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
fix(node): wrong worker_threads.terminate()
return value (#23803)
<!-- Before submitting a PR, please read https://docs.deno.com/runtime/manual/references/contributing 1. Give the PR a descriptive title. Examples of good title: - fix(std/http): Fix race condition in server - docs(console): Update docstrings - feat(doc): Handle nested reexports Examples of bad title: - fix #7123 - update docs - fix bugs 2. Ensure there is a related issue and it is referenced in the PR text. 3. Ensure there are tests that cover the changes. 4. Ensure `cargo test` passes. 5. Ensure `./tools/format.js` passes without changing files. 6. Ensure `./tools/lint.js` passes. 7. Open as a draft PR if your work is still in progress. The CI won't run all steps, but you can add '[ci]' to a commit message to force it to. 8. If you would like to run the benchmarks on the CI, add the 'ci-bench' label. --> Fixes https://github.com/denoland/deno/issues/23801 --------- Signed-off-by: Marvin Hagemeister <marvinhagemeister50@gmail.com> Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
parent
e661591e7c
commit
e02d0faedc
2 changed files with 29 additions and 1 deletions
|
@ -32,6 +32,7 @@ import process from "node:process";
|
|||
const { JSONParse, JSONStringify, ObjectPrototypeIsPrototypeOf } = primordials;
|
||||
const {
|
||||
Error,
|
||||
PromiseResolve,
|
||||
Symbol,
|
||||
SymbolFor,
|
||||
SymbolIterator,
|
||||
|
@ -280,7 +281,8 @@ class NodeWorker extends EventEmitter {
|
|||
this.#status = "TERMINATED";
|
||||
op_host_terminate_worker(this.#id);
|
||||
}
|
||||
this.emit("exit", 1);
|
||||
this.emit("exit", 0);
|
||||
return PromiseResolve(0);
|
||||
}
|
||||
|
||||
ref() {
|
||||
|
|
|
@ -516,6 +516,32 @@ Deno.test({
|
|||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "[node/worker_threads] Returns terminate promise with exit code",
|
||||
async fn() {
|
||||
const deferred = Promise.withResolvers<void>();
|
||||
const worker = new workerThreads.Worker(
|
||||
`
|
||||
import { parentPort } from "node:worker_threads";
|
||||
parentPort.postMessage("ok");
|
||||
`,
|
||||
{
|
||||
eval: true,
|
||||
},
|
||||
);
|
||||
|
||||
worker.on("message", (data) => {
|
||||
assertEquals(data, "ok");
|
||||
deferred.resolve();
|
||||
});
|
||||
|
||||
await deferred.promise;
|
||||
const promise = worker.terminate();
|
||||
assertEquals(typeof promise.then, "function");
|
||||
assertEquals(await promise, 0);
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name:
|
||||
"[node/worker_threads] MessagePort.on all message listeners are invoked",
|
||||
|
|
Loading…
Reference in a new issue