Created
July 24, 2012 15:25
-
-
Save bobrik/3170653 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var shouldCall = false; | |
function first() { | |
console.log("first callback") | |
if (!shouldCall) { | |
shouldCall = true; | |
} else { | |
firstFinal(); | |
} | |
} | |
function second() { | |
console.log("second callback") | |
if (!shouldCall) { | |
shouldCall = true; | |
} else { | |
firstFinal(); | |
} | |
} | |
function firstFinal() { | |
console.log("first finished"); | |
} | |
setTimeout(first, 500); | |
setTimeout(second, 1000); | |
})(); | |
// output: | |
// first callback | |
// second callback | |
// first finished |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment