Skip to content

Instantly share code, notes, and snippets.

@sacgov
Created June 13, 2019 11:37
Show Gist options
  • Save sacgov/853ce8f25cc92787046d5424a32caa32 to your computer and use it in GitHub Desktop.
Save sacgov/853ce8f25cc92787046d5424a32caa32 to your computer and use it in GitHub Desktop.
async job example
const executeAfterJob = () => {
// pop a notification
console.log("finally my job is done now")
}
const functionThatTakesTime = ( executeAfterJob) => {
setTimeout(executeAfterJob, 5000)
}
const executeJobSync = () => {
var stop = new Date().getTime();
while(new Date().getTime() < stop + 5000) {
;
}
}
console.log('Before sync Job');
executeJobSync();
console.log('after sync job before async job');
functionThatTakesTime(executeAfterJob);
console.log('I dont need to wait for anyone');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment