Created
September 6, 2017 21:18
-
-
Save nate-getch/c40868e83ec117e3347d5d92b9522461 to your computer and use it in GitHub Desktop.
Simple code showing Async and Sync features in Node.js
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
function syncfunc(a, callbackfn){ | |
callbackfn("this is sync"); | |
} | |
syncfunc('temp', function(r){ console.log(r) }); | |
console.log("done sync func"); | |
function asyncfunc(a, callbackfn){ | |
process.nextTick( () => callbackfn("this is async") ); | |
} | |
asyncfunc('temp', function(r){ console.log(r) }); | |
console.log("done async func"); | |
// code output | |
/* | |
this is sync | |
done sync func | |
done async func | |
this is async | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment