Skip to content

Commit 5fc4e48

Browse files
addaleaxBridgeAR
authored andcommitted
doc: add note about AsyncResource for Worker pooling
When implementing a pool for Worker threads, the correlation between posting tasks and getting their results may get lost, depending on the implementation. The `AsyncResource` API is the primary way to solve that issue, so link it from the recommendation in the worker docs. (This was brought up at the collaborator summit in Berlin.) PR-URL: #28023 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
1 parent b491eab commit 5fc4e48

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

doc/api/worker_threads.md

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ The above example spawns a Worker thread for each `parse()` call. In actual
4949
practice, use a pool of Workers instead for these kinds of tasks. Otherwise, the
5050
overhead of creating Workers would likely exceed their benefit.
5151

52+
When implementing a worker pool, use the [`AsyncResource`][] API to inform
53+
diagnostic tools (e.g. in order to provide asynchronous stack traces) about the
54+
correlation between tasks and their outcomes.
55+
5256
## worker.isMainThread
5357
<!-- YAML
5458
added: v10.5.0
@@ -653,6 +657,7 @@ active handle in the event system. If the worker is already `unref()`ed calling
653657
`unref()` again will have no effect.
654658

655659
[`'close'` event]: #worker_threads_event_close
660+
[`AsyncResource`]: async_hooks.html#async_hooks_class_asyncresource
656661
[`Buffer`]: buffer.html
657662
[`EventEmitter`]: events.html
658663
[`EventTarget`]: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget

0 commit comments

Comments
 (0)