Git Product home page Git Product logo

Comments (2)

itler90 avatar itler90 commented on August 22, 2024 1

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.

metcoder95 avatar metcoder95 commented on August 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.