Skip to content
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 can I achieve the automatic start of a task if space is freed up in the queue? #662

Open
Borodin opened this issue Aug 4, 2022 · 0 comments

Comments

@Borodin
Copy link

Borodin commented Aug 4, 2022

I expect the queue to refill automatically as it becomes free.

const queue = new Queue({
    concurrent: 3,
    start: true,
    interval: 0
});
queue.on("resolve", n => {
    console.log(n);
});

[10, 10, 1, 1, 1, 1, 1, 1, 1].forEach(n => {
    queue.enqueue(async () => {
        await new Promise((resolve) => {
            setTimeout(resolve, n*1000);
        });
        return n;
    })
})

In this code, I want the fourth task to be executed after the completion of the third one. But in fact, the 4 task will be completed only after the completion of the first two.

return:

1
10, 10
1, 1, 1
1, 1, 1

I expect:

1
1 
1
1
1
1
1
10, 10

How can I achieve the automatic start of a task if space is freed up in the queue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant