Skip to content

Commit 8dbc6b2

Browse files
jasnelladuh95
authored andcommitted
worker: make Worker async disposable
PR-URL: #58385 Backport-PR-URL: #58455 Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Daeyeon Jeong <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]>
1 parent 6905258 commit 8dbc6b2

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

doc/api/worker_threads.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,14 @@ Calling `unref()` on a worker allows the thread to exit if this is the only
18461846
active handle in the event system. If the worker is already `unref()`ed calling
18471847
`unref()` again has no effect.
18481848

1849+
### `worker[Symbol.asyncDispose]()`
1850+
1851+
<!-- YAML
1852+
added: REPLACEME
1853+
-->
1854+
1855+
Alias for [`worker.terminate()`][].
1856+
18491857
## Notes
18501858

18511859
### Synchronous blocking of stdio

lib/internal/worker.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const {
5858
const { createMainThreadPort, destroyMainThreadPort } = require('internal/worker/messaging');
5959
const { deserializeError } = require('internal/error_serdes');
6060
const { fileURLToPath, isURL, pathToFileURL } = require('internal/url');
61-
const { kEmptyObject } = require('internal/util');
61+
const { kEmptyObject, SymbolAsyncDispose } = require('internal/util');
6262
const { validateArray, validateString } = require('internal/validators');
6363
const {
6464
throwIfBuildingSnapshot,
@@ -406,6 +406,10 @@ class Worker extends EventEmitter {
406406
});
407407
}
408408

409+
async [SymbolAsyncDispose]() {
410+
await this.terminate();
411+
}
412+
409413
ref() {
410414
if (this[kHandle] === null) return;
411415

0 commit comments

Comments
 (0)