function test_sleep() {
var sleep = require('sleep');
sleep.sleep(5);
}
test_sleep();
I use pstree to show threads for node
│ ├─bash─┬─node───2*[{node}]
│ │ └─pstree
my node version is v0.11.3
I tried this code in v0.6.3,And there's only one thread. so what's the differece between this two versions?
-- Ben NoordhuisNode.js (or rather libuv) maintains a small pool of worker threads. Threads are fairly expensive to spin up and tear down, that's why they stay around.
These threads are used to conduct I/O operations without blocking the main event loop. See Basics of libuv.