New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Await all work currently in the queue #65
Comments
This would a be a good feature to have. Adding it to the promise implementation would be nice, i.e. Note that your implementation accumulates a lot of data in the queue, while I would do something like:
Would you like to send a PR? |
I found out about Changes my example to: const worker = (obj) => new Promise(resolve => setTimeout(resolve, 2000)).then(() => console.log(obj))
const q = fastq.promise(worker, 10);
let count = 0;
for await (const obj of asyncIteratorThatYieldsALOT) {
q.push(obj).catch(e => { throw e }); // note I want the error to bubble up
count++;
}
await q.drained();
console.log("Nr of obj processed:", count) Still thinking about your back pressure comment. |
Experimented some more, couple of observations:
For that last point, would it be nice to have a function like this?:
The return promise would resolve:
Perhaps it should take an argument whereby you can indicate the amount of items on the queue you're willing to accept (i.e. like a
Or perhaps such a -- But long story short: my issue is resolved, I can await all work in the queue. We could close this issue. |
I think a PR to implement some "back pressure streaming" support for the queue would be amazing. |
I'll try to have a stab at that! |
I'd like to be able to await all work in the queue. (I use fastq to limit the amount of parallel work being done and create a new ephemeral queue every time I need to do this work)
Currently I'm doing this, which I don't like:
Is there a better way?
Otherwise, I'd be open to contribute this feature?
The text was updated successfully, but these errors were encountered: