From 5fc4e48fdd138652d708158ba3035c2947ad9d4c Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 2 Jun 2019 16:09:14 +0200 Subject: [PATCH] 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 Reviewed-By: Colin Ihrig Reviewed-By: Ruben Bridgewater Reviewed-By: Gireesh Punathil --- doc/api/worker_threads.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/api/worker_threads.md b/doc/api/worker_threads.md index 000851bc8a3c0a..27d4fb2a6a62fb 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