Reputation: 1125
Does Array.sort block the main thread in node.js from start to finish? If yes, is there a library that does an incremental sort (i.e. an array sort that will sort in chunks, possibly utilizing Process.nextTick ?)
Thanks!
Upvotes: 7
Views: 3247
Reputation: 1
Not to be confused with a multi-threaded sort, this demo of HTML5 Web Workers shows you how to sort in a separate thread thereby freeing up your main thread to do other things.
Upvotes: 0
Reputation: 8572
the short answer as you guys figured is nope.
More of a conceptual answer, async is meant to solve waiting for resource issues, and not heavy calculations at all
With that said, nothing stops you from having sort running in another process, and communicating with it asynchronously
I'd just be careful specially with 2 things: don't start a new process for each sort is probably a good idea if startup take some time. If you have a big array be careful with memory copy what you are sorting, if you have to anyway, you may just return the ordered indexes in the array ;)
Upvotes: 2