You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
runTask(task, callback) {
if (this.freeWorkers.length === 0) {
// No free threads, wait until a worker thread becomes free.
this.once(kWorkerFreedEvent, () => this.runTask(task, callback));
return;
}
// ...
Since this code snippet is presented explicitly as how to do something and is very much code that developers could easily end up copy-pasting into their own codebase, I figured it was worth raising as a potential issue.
This code has 2 issues:
This quickly triggers a MaxListenersExceededWarning since it adds a listener for every queued task and that number is unbounded
This is O(N^2) because when the kWorkerFreedEvent fires, it fires every callback (even though N-1 will just be re-queued), and once listeners have to do a linear search to remove themselves when they fire
Thoughts?
✍️
I would like to work on this issue and
submit a pull request.
The text was updated successfully, but these errors were encountered:
📗 API Reference Docs Problem
Location
The example WorkerPool using async_hooks
Affected URL(s):
Description
The code I'm explicitly concerned about is
Since this code snippet is presented explicitly as how to do something and is very much code that developers could easily end up copy-pasting into their own codebase, I figured it was worth raising as a potential issue.
This code has 2 issues:
MaxListenersExceededWarning
since it adds a listener for every queued task and that number is unboundedkWorkerFreedEvent
fires, it fires every callback (even though N-1 will just be re-queued), andonce
listeners have to do a linear search to remove themselves when they fireThoughts?
✍️
submit a pull request.
The text was updated successfully, but these errors were encountered: