Skip to content

Instantly share code, notes, and snippets.

@bobrik
Created July 24, 2012 15:25
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 bobrik/3170653 to your computer and use it in GitHub Desktop.
Save bobrik/3170653 to your computer and use it in GitHub Desktop.
(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