Following this link http://greenash.net.au/thoughts/2012/11/nodejs-itself-is-blocking-only-its-io-is-non-blocking/ I'm trying to code two non-blocking functions:
blocking code:
function LongBucle() {
for (x=0;x<=10000;x++) {
console.log(x);
}
}
function ShortBucle() {
for (x=0;x<=10;x++) {
console.log("short "+x);
}
}
LongBucle();
console.log("Long bucle end");
ShortBucle();
console.log("Short bucle end");
Now I try to turn the code into non blocking code so the "console.log("Short bucle end");" should be shown first?
function ShortBucle(callback) {
for (x=0;x<=10;x++) {
console.log("corto "+x);
}
callback(x);
}
function LongBucle(callback) {
for (x=0;x<=10000;x++) {
console.log(x);
}
callback(x);
}
LongBucle(function(err) {
console.log('Long bucle end');
});
ShortBucle(function(err) {
console.log('short bucle end');
});
But it doesn't work. What am I doing wrong?
setImmediate