Skip to content

Instantly share code, notes, and snippets.

@nate-getch
Created September 6, 2017 21:18
Show Gist options
  • Save nate-getch/c40868e83ec117e3347d5d92b9522461 to your computer and use it in GitHub Desktop.
Save nate-getch/c40868e83ec117e3347d5d92b9522461 to your computer and use it in GitHub Desktop.
Simple code showing Async and Sync features in Node.js
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