Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5fc4e48

Browse filesBrowse 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 <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
1 parent b491eab commit 5fc4e48
Copy full SHA for 5fc4e48

File tree

Expand file treeCollapse file tree

1 file changed

+5
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+5
-0
lines changed
Open diff view settings
Collapse file

‎doc/api/worker_threads.md‎

Copy file name to clipboardExpand all lines: doc/api/worker_threads.md
+5Lines changed: 5 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.