question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to sort an async queue?

See original GitHub issue

Hey 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:closed
  • Created 7 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
megawaccommented, Nov 1, 2016

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

var q = async.queue(worker);
q._tasks = new Heap();
0reactions
aearlycommented, Jul 20, 2016

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Sort a List in Java 8 - Async Queue
We have two options, we can use either Collections class or Java stream API with the Sort method. When we have custom objects...
Read more >
Async sort(by:) - Using Swift - Swift Forums
I'm trying to sort a collection using sorted(by:) , but the closure requires an async function. Something similar to this:
Read more >
How to use std::async on a queue of vectors ... - Stack Overflow
All you need is to create vector for holding future objects, iterate over queue and at each iterator call async function to start ......
Read more >
Queues — Python 3.11.1 documentation
Block until all items in the queue have been received and processed. The count of unfinished tasks goes up whenever an item is...
Read more >
async - Documentation - GitHub Pages
An async function to apply to each item in coll . The iteratee should complete with a value to use as the sort...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found