diff options
-rw-r--r-- | ext/node/polyfills/worker_threads.ts | 4 | ||||
-rw-r--r-- | tests/unit_node/worker_threads_test.ts | 26 |
2 files changed, 29 insertions, 1 deletions
diff --git a/ext/node/polyfills/worker_threads.ts b/ext/node/polyfills/worker_threads.ts index 71999dd62..36314675a 100644 --- a/ext/node/polyfills/worker_threads.ts +++ b/ext/node/polyfills/worker_threads.ts @@ -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() { diff --git a/tests/unit_node/worker_threads_test.ts b/tests/unit_node/worker_threads_test.ts index f46d982fe..e16bc8966 100644 --- a/tests/unit_node/worker_threads_test.ts +++ b/tests/unit_node/worker_threads_test.ts @@ -517,6 +517,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", async fn() { |