Skip to content

Instantly share code, notes, and snippets.

@nickylimjj
Created July 1, 2016 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickylimjj/247c6ed05c6efcd49b9e5d5e8ac7f4b3 to your computer and use it in GitHub Desktop.
Save nickylimjj/247c6ed05c6efcd49b9e5d5e8ac7f4b3 to your computer and use it in GitHub Desktop.
NodeJS: non-blocking I/O
// understanding the Event Loop and async nature of nodejs
// resource help from : https://www.codeschool.com/blog/2014/10/30/understanding-node-js/
function submitOrder(orderNumber){
console.log('Submitted order and cooking: ' + orderNumber)
cookingFood(function afterEvent(){
console.log('food is cooked and ready to be delivered')
})
}
// 5s operation
function cookingFood(cb){
setTimeout(cb,5000)
}
submitOrder(1)
submitOrder(2)
submitOrder(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment