From 68380b6d6b5b5bd8ea0a66719f31649dc18845e4 Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Sat, 16 Apr 2022 18:17:50 +0530 Subject: [PATCH] worker: add hasRef() This should help projects like https://github.com/mafintosh/why-is-node-running and https://github.com/facebook/jest to detect if Worker instances are keeping the event loop active correctly. Fixes: https://github.com/nodejs/node/issues/42091 Refs: https://github.com/mafintosh/why-is-node-running/issues/59 Signed-off-by: Darshan Sen --- doc/api/worker_threads.md | 10 ++++++++++ lib/internal/worker.js | 6 ++++++ src/node_worker.cc | 8 ++++++++ src/node_worker.h | 1 + test/parallel/test-worker-hasref.js | 12 ++++++++++++ 5 files changed, 37 insertions(+) create mode 100644 test/parallel/test-worker-hasref.js diff --git a/doc/api/worker_threads.md b/doc/api/worker_threads.md index 3e8158470d432f..4a35f381c3067c 100644 --- a/doc/api/worker_threads.md +++ b/doc/api/worker_threads.md @@ -1144,6 +1144,16 @@ Send a message to the worker that is received via [`require('worker_threads').parentPort.on('message')`][]. See [`port.postMessage()`][] for more details. +### `worker.hasRef()` + + + +> Stability: 1 - Experimental + +If true, the `Worker` object will keep the Node.js event loop active. + ### `worker.ref()`