How to sort an async queue?
See original GitHub issueHey there
Before version 2.0.0 of async I was using the queue.tasks
array to manually re-sort the queue after the items have already been pushed to the queue.
I just used array.sort
and it was working perfectly fine for my use case.
The switch to Doubly Linked Lists in v2.0.0 unfortunately broke my implementation.
Now my question: Is there an easy way to sort an async.queue
on the fly?
Of course I could always drain the queue, sort everything and pump it back into the queue, but it would be nice if there was some way to directly sort on the async queue.
If this is indeed not built into async.queue
yet, I could try to implement it.
It could imagine something like queue.sort(compareFunction)
that accepts a compareFunction
similar to array.sort
.
var points = [40, 100, 1, 5, 25, 10];
points.sort(function(a, b){return a-b});
Unfortunately I don’t really know how easy that would be with Doubly Linked Lists, since I’m not very familiar with those.
Best, Sandro
Issue Analytics
- State:
- Created 7 years ago
- Comments:9
Top GitHub Comments
Yeah, I don’t think this makes sense to belong in async proper. I don’t think the tradeoffs are worth it. It would be awesome if someone implemented a heap that was compatible with our queue (so you could do
So we would use a heap for
priorityQueue
s only? I don’t see how a heap would benefit an ordinary queue.A heap also wouldn’t help @sandromartis 's use case much. He’d get O(nlogn) sorts, but he’s still have to resort manually.