Rich-Harris/yootils

Change behavior to close after queue is empty

bwbroersma opened this issue · 3 comments

Currently yootils queue is set to close before actually finishing the promise, making it unpractical to add a task, await queue.close() and in that task adding more tasks, which will currently fail because close = true is set on calling awaiting close.

close() {
closed = true;
return new Promise((fulfil, reject) => {
if (pending === 0) {
fulfil();
} else {
fulfil_closed = fulfil;
}
});
}

Thank you! Sorry for the delayed response. I'm not sure if these are the most desirable semantics though — isn't it confusing if you can add a task after calling q.close()?

I do like the idea of q.close returning a promise that resolves when all items have completed though.

Yeah, I agree, it was mainly a fix to sveltejs/sapper#604 and it's more a closeWhenEmpty now.

Found an alternative solution in sveltejs/sapper#605, so we can keep the existing semantics of q.close — I'll close this. I've merged the additional tests from #4 though — thank you!