Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array.sort and Node.js

Tags:

node.js

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!

like image 803
cortfr Avatar asked Oct 12 '12 16:10

cortfr


People also ask

How do you sort an array in node?

sort() is an array function from Node. js that is used to sort a given array. Parameter: This function does not takes any parameter. Return type: The function returns the sorted array.

What does arrays sort () do?

The sort() sorts the elements of an array. The sort() overwrites the original array. The sort() sorts the elements as strings in alphabetical and ascending order.

How do you sort an array in ascending order?

Example: Sort an Array in Java in Ascending Order Then, you should use the Arrays. sort() method to sort it. That's how you can sort an array in Java in ascending order using the Arrays. sort() method.


1 Answers

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

like image 183
Fabiano Soriani Avatar answered Oct 19 '22 12:10

Fabiano Soriani