Comments (2)
Hi @metcoder95,
Thanks for your quick response!
I already saw the drain
event but my main goal is to wait for all elements are executed completely. Now I just implemented a workaround:
I introduced a global variable finished
as counter. Within the task argument of the piscina.run
call I increment the counter. So I'm sure that each task has been finished and after that the counter is incremented. Next to the for-loop of the piscina.run
calls I added following (with maxLength
== 20 in my example above):
while (finished != maxLength)
{
await Sleep(100);
}
So every 100 ms I check whether my counter reached my max element size and thus I can detect that all tasks have been executed completely.
For me this issue is closed. Thanks again for your response! 😄
from piscina.
Hey!
First, yes, as you already said the erro is working as expected; the close
method won't wait for the queue to be flushed but rather that all running tasks are done before closing. Tho, the event is quite interesting because it might mean that something is causing the worker to report back the state in a delayed manner.
Second, not sure what your main goal is, but if you are seeking to see when its time to add more tasks to the queue, I'd definitely suggest you to use the drain
event from Piscina.
e.g.
const { once } = require('node:event');
// Piscina code
await once(piscina, 'drain');
This event is triggered when the pool has room capacity for adding more tasks.
What I acknowledge is that we do not have an event for when pool and its task queue is totally empty, maybe adding something like idle
event can be of support.
from piscina.
Related Issues (20)
- Errors thrown from Node vm.Script cause pool.run() to resolve to null instead of rejecting HOT 3
- Error [ERR_MODULE_NOT_FOUND]: Cannot find module '...\app.asar\out\main\worker.js' imported from ...\app.asar\node_modules\piscina\dist\src\worker.js HOT 3
- Express js
- RangeError in Piscina -> RecordableHistogram HOT 3
- Can worker objects be emitted together during the emit event? HOT 3
- When I try to send a message to the worker thread, an error occurs HOT 3
- docs: New documentation site HOT 7
- Expose `Task` and `TaskQueue` interfaces HOT 1
- Update supported Nodejs version in docs HOT 3
- Class extends value undefined is not a constructor or null HOT 8
- Error: TypeError: (0 , os_1.availableParallelism) is not a function
- ReferenceError [Error]: module is not defined in ES module scope HOT 3
- Fast API HOT 2
- package.json is parsed at static path
- Using Pino Transports <> Piscina results in extra worker_threads for log transports HOT 3
- chore: Migrate tests from Tap to `node:test` HOT 1
- Stream example results in MaxListenersExceededWarning HOT 4
- Can you add an example to README as to how to broadcast a message to all worker threads using `BroadcastChannel` (Node v18+)? HOT 1
- Core bug with `piscina.close()` method, which calls `terminate` and `await Promise.all(exitEvents)` HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from piscina.