Skip to content

Instantly share code, notes, and snippets.

@ellman
Last active May 3, 2022 11:22
Show Gist options
  • Save ellman/8576959 to your computer and use it in GitHub Desktop.
Save ellman/8576959 to your computer and use it in GitHub Desktop.
Simple Nodejs callback example
// Simulate some slow I/O task
function blockingIO(callback) {
// Delay of 3 seconds
setTimeout(function() {
callback("The blocking task has been completed");
}, 3000);
}
// A demo callback function
function doThisWhenFinished(message) {
// All it does it console logs the messgae
console.log(message);
}
// Calling our simulated I/O function
blockingIO(doThisWhenFinished);
// The event loop continues
console.log("Prints before the IO tasks finishes");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment