-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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() #1397
queue.remove() #1397
Conversation
lib/internal/DoublyLinkedList.js
Outdated
return arr; | ||
} | ||
|
||
DLL.prototype.filter = function (testFn) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this destructive? If so I'd rather not call it filter
, but remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to call it filter
so that if someone wants to swap out the implementation of _tasks
with an array, they could. e.g.:
var q = async.queue(worker);
q._tasks = [];
I remember we got an issue a while back after 2.0 because some people were doing custom splicing in the queue, which they couldn't do with the linked list.
It is strange that it doesn't return a new list (destructive) even though it's called filter
, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually after more thought, remove
is a better name. If someone is using an array implementation, they're likely doing their own array splicing somehow anyway.
lib/internal/queue.js
Outdated
remove: function (testFn) { | ||
q._tasks = q._tasks.filter(function (node) { | ||
return !testFn(node); | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: missing semi
Closes #1391 .
Adds a
remove
function to queues. Without it, there is no way to arbitrarily remove items from the queue. In Async 1.x and below, thetasks
list was just an array, so you could splice as you needed. This adds afilter
function to theDoublyLinkedList
class that is used byq.remove
.I also added some unit tests for
DLL
itself. I also noticed that the prior implementation ofempty
could cause a memory leak. I think the lingering chain ofprev
/next
references could fool GC and keep the objects around.