-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
[FEATURE REQUEST] flush option #8
Comments
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? |
@ForbesLindesay That would be an extremely useful utility function! 💯 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: