Created
June 13, 2019 11:37
-
-
Save sacgov/853ce8f25cc92787046d5424a32caa32 to your computer and use it in GitHub Desktop.
async job example
This file contains 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
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