We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
not sure how this would work API-wise, but the idea is to return a promise somewhere that resolves then there is no longer any promises in the queue.
const fn = throat(3, myOtherFunction) fn(1) fn(2) fn(3) fn(4) fn.flush().then(doSomethingElse())
it should resolve immediately if there are no more functions in the queue. flush should throw if any of the promises in the queue failed.
The text was updated successfully, but these errors were encountered:
Interesting thought. This could be done as an extra wrapper:
// untested function collector(fn) { var inProgress = 0; var waiting = []; function end() { inProgress--; if (inProgress === 0) { while (waiting.length) waiting.pop()(); } } function run() { var result = fn.apply(this, arguments); inProgress++; result.then(end, end); return result; } function flush() { return new Promise(function (resolve) { if (inProgress) waiting.push(resolve); else resolve(); }); } run.flush = flush; return run; }
Then:
const fn = collector(throat(3, myOtherFunction) fn(1) fn(2) fn(3) fn(4) fn.flush().then(() => doSomethingElse())
Might be a useful utility function to publish?
Sorry, something went wrong.
@ForbesLindesay That would be an extremely useful utility function! 💯
No branches or pull requests
not sure how this would work API-wise, but the idea is to return a promise somewhere that resolves then there is no longer any promises in the queue.
it should resolve immediately if there are no more functions in the queue. flush should throw if any of the promises in the queue failed.
The text was updated successfully, but these errors were encountered: