7

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!

2 Answers 2

2

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 ;)

Sign up to request clarification or add additional context in comments.

Comments

0

Sorting in a separate thread

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.