Skip to content

Instantly share code, notes, and snippets.

@ruzz311
Last active March 4, 2017 18:34
Show Gist options
  • Save ruzz311/15a60dd674fcb623f6f7 to your computer and use it in GitHub Desktop.
Save ruzz311/15a60dd674fcb623f6f7 to your computer and use it in GitHub Desktop.
An old-school mindset actually showed me this once and asked how node is not blocking. If you say "callback hell" is a reason you don't adopt node at this point(2015) you should probably sit with in the corner with the cobol engineers. (you guys make great money and there's still demand, but who wants to work with that?)
OH_SHIT_I_NEED_GLOBALS = 100001;
function iWantThis () {
while (count < window.OH_SHIT_I_NEED_GLOBALS) {
count = Math.random()*100000;
}
return "I haven't googled node yet. How does threads happen? So blocking, much crap."
}
iWantThis();
@simshanith
Copy link

Works a bit differently, but same general idea in a less blocking manner

function iWillWantThis(max) {
  return new Promise(function(resolve)  {
    resolve(Math.random() * max);
  });
}

function iWantSoMany(max) {
  return Promise.all(_.map(_.range(0, max),  _.partial(iWillWantThis, max)));
}

iWantSoMany(1e6+1).then(function(soMany) {
  console.log('so many! %s random numbers! first one is %s', soMany.length, _.first(soMany));
});

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