worker: make Worker async disposable · nodejs/node@aeb9ab4

Original file line numberDiff line numberDiff line change

@@ -1861,6 +1861,21 @@ Calling `unref()` on a worker allows the thread to exit if this is the only

18611861

active handle in the event system. If the worker is already `unref()`ed calling

18621862

`unref()` again has no effect.

18631863
1864+

### `worker[Symbol.asyncDispose]()`

1865+
1866+

<!-- YAML

1867+

added: REPLACEME

1868+

-->

1869+
1870+

Calls [`worker.terminate()`][] when the dispose scope is exited.

1871+
1872+

```js

1873+

async function example() {

1874+

await using worker = new Worker('for (;;) {}', { eval: true });

1875+

// Worker is automatically terminate when the scope is exited.

1876+

}

1877+

```

1878+
18641879

## Notes

18651880
18661881

### Synchronous blocking of stdio