summaryrefslogtreecommitdiff
path: root/doc/api/worker_threads.md
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-06-02 16:09:14 +0200
committerAnna Henningsen <anna@addaleax.net>2019-06-10 15:20:54 +0200
commit55de20999b8b60a7ef889ea0d9573e9f271e1d17 (patch)
tree7d393bfb94457ac93dbd9f245e14ab3621cf7ffe /doc/api/worker_threads.md
parentcde3928a10627510ae0aee7728e5498a95235482 (diff)
downloadandroid-node-v8-55de20999b8b60a7ef889ea0d9573e9f271e1d17.tar.gz
android-node-v8-55de20999b8b60a7ef889ea0d9573e9f271e1d17.tar.bz2
android-node-v8-55de20999b8b60a7ef889ea0d9573e9f271e1d17.zip
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: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'doc/api/worker_threads.md')
-rw-r--r--doc/api/worker_threads.md5
1 files changed, 5 insertions, 0 deletions
diff --git a/doc/api/worker_threads.md b/doc/api/worker_threads.md
index 000851bc8a..27d4fb2a6a 100644
--- a/doc/api/worker_threads.md
+++ b/doc/api/worker_threads.md
@@ -49,6 +49,10 @@ The above example spawns a Worker thread for each `parse()` call. In actual
practice, use a pool of Workers instead for these kinds of tasks. Otherwise, the
overhead of creating Workers would likely exceed their benefit.
+When implementing a worker pool, use the [`AsyncResource`][] API to inform
+diagnostic tools (e.g. in order to provide asynchronous stack traces) about the
+correlation between tasks and their outcomes.
+
## worker.isMainThread
<!-- YAML
added: v10.5.0
@@ -653,6 +657,7 @@ active handle in the event system. If the worker is already `unref()`ed calling
`unref()` again will have no effect.
[`'close'` event]: #worker_threads_event_close
+[`AsyncResource`]: async_hooks.html#async_hooks_class_asyncresource
[`Buffer`]: buffer.html
[`EventEmitter`]: events.html
[`EventTarget`]: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget