-
-
Notifications
You must be signed in to change notification settings - Fork 96
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
how should i use clearqueue? #49
Comments
I don't understand the question. I think the docs are pretty clear about it. |
I have an variable named 'switch' and a vue watcher to watch 'switch' ; if 'switch' is false,then I want to stop all the tasks pending in the limit queue.
but the tasks is still running to the end. The code cannot stop the tasks in the queue |
You cannot stop the "active" tasks. |
Thanks for reply!!! Yes! I just want to stop the pending tasks . As your example const pLimit = require('p-limit');
const limit = pLimit(1);
const input = [
limit(() => fetchSomething('foo')),
limit(() => fetchSomething('bar')),
limit(() => doSomething())
// ......if there are 1000 functions
];
(async () => {
// Only one promise is run at once
const result = await Promise.all(input);
console.log(result);
})(); if I have 1000 limit(() => myfunction()) In this period, may be there are 500 pending rasks, 1 running tasks, and 499 finished tasks. I just want to stop these 500 pending tasks when a variable called "switch" is true. But i don't know how to use limit.clearQueue() if (this.switch) {
this.limit.clearQueue()
} Could U give me an example? |
You could do something like this: const pLimit = require('p-limit');
const limit = pLimit(1);
const check = fn => {
if (switch) {
limit.clearQueue();
}
fn();
};
const input = [
limit(check(() => fetchSomething('foo'))),
limit(check(() => fetchSomething('bar'))),
limit(check(() => doSomething()))
// ......if there are 1000 functions
];
(async () => {
// Only one promise is run at once
const result = await Promise.all(input);
console.log(result);
})(); |
I want to stop the pending tasks
The text was updated successfully, but these errors were encountered: