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

queue.remove() with filter function #1391

Closed
robsch opened this issue Mar 28, 2017 · 3 comments
Closed

queue.remove() with filter function #1391

robsch opened this issue Mar 28, 2017 · 3 comments

Comments

@robsch
Copy link

robsch commented Mar 28, 2017

I'm currently finding a way to remove certain unprocessed entries in a queue/priorityQueue. I don't know how to do it, so I would appreciate if anyone could give me a hint.

Feature suggestion: add another method with which entries gets removed like that:

var q = async.queue(function (task, callback) {
    callback();
});
q.push({some: 'thing'});
q.remove(function (task) {
    return task.some === 'thing'; // remove task if return value is true
});

Or with the priority queue:

var q = async.priorityQueue(function (task, callback) {
    callback();
}, 3);
q.push({some: 'thing'}, 100);
q.remove(function (task, priority) {
    return task.some === 'thing'; // remove task if return value is true
    or
    return priority === 100; // remove task with certain priority
});
@aearly
Copy link
Collaborator

aearly commented Mar 31, 2017

We expose the underlying tasks as q._tasks. It is a linked list, rather than an array, however.

@megawac what do you think is the best solution for removing an item from the queue? Add a filter function to the DLL?

@megawac
Copy link
Collaborator

megawac commented Mar 31, 2017

I think this is reasonable, I prefer the name remove than filter as remove implies destructiveness

@robsch
Copy link
Author

robsch commented Apr 4, 2017

Now, I've done it with collecting the tasks first and then remove them in a second step. I wasn't sure what would happen if I remove them immediately.

You could implement both: filter and remove, though I needed only the remove function.

Compared to the kill function I wouldn't remove the drain function when remove is called.

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

No branches or pull requests

3 participants