Skip to content

Instantly share code, notes, and snippets.

@addisaden
Created December 1, 2012 13:42
Show Gist options
  • Select an option

  • Save addisaden/4182302 to your computer and use it in GitHub Desktop.

Select an option

Save addisaden/4182302 to your computer and use it in GitHub Desktop.
Why is this code blocking?
var worker_clb = function(name, clb) {
var d = new Date();
for(var i = 0; i < 100000000; i++) {
i+i;
}
clb(name + "_clb returns after " + ((new Date()) - d) + " ms.");
}
var a_lot_to_do = function(name, clb) {
worker_clb(name, clb);
clb(name + " is fired");
}
a_lot_to_do("w1", console.log);
a_lot_to_do("w2", console.log);
a_lot_to_do("w3", console.log);
a_lot_to_do("w4", console.log);
@sameei
Copy link

sameei commented Nov 30, 2013

No; Output is true! You're only one thread to run your code! so NodeJs runs "worker_clb" and next runs " clb(name + " is fired");". your code isn't async || non-blocking !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment