npm i qsort-async
While working with a rather large dataset, I noticed that a sort was blocking all I/O operations for my application. While this is fine for smaller arrays and datasets, I needed a sort that would yield to IO; specifically input from devices and web server requests.
const quicksort = ;const arr = 3 1 2;await ;// arr [1, 2, 3];
const quicksort = ;const arr = 'c' 'a' 'b';await;// arr ['a', 'b', 'c'];
sort ( array, compare, [ size=10000 ] )
- array - The array to sort in place
- compare - function to compare elements of array
- size - The size minimum at which setImmediate is skipped
- if your compare function takes some time to execute, consider lowering this to yield to the eventloop/io more often
- in theory, you could lower this all the way to 1, but this does not make sense for smaller arrays
Add a version that accepts an async comparator... but do you need it?