Skip to content

Instantly share code, notes, and snippets.

@NeoTech
Last active September 22, 2015 13:56
Show Gist options
  • Save NeoTech/66e5cef7b75613c0f87e to your computer and use it in GitHub Desktop.
Save NeoTech/66e5cef7b75613c0f87e to your computer and use it in GitHub Desktop.
Asynchron IO and how it executes.
/**
* Created by WARMACHINE on 2015-09-22.
*/
// Example of code execution in a asynchron enviroment
// For simulate lag from db, timeouts will be used.
console.log('I will execute first');
var delay1 = 0;
setTimeout((function() {
delay1 = 1;
console.log('I\'m since long forgotten');
}), 500);
if(delay1) {
console.log('I will execute when timeout is done.');
} else {
console.log('I did not execute at all.');
}
console.log('I will execute third');
if((function() { return setTimeout((function() { return true; }),500)})) {
console.log('But we will wait for this.');
}
console.log('Before this...');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment