Last active
May 3, 2022 11:22
-
-
Save ellman/8576959 to your computer and use it in GitHub Desktop.
Simple Nodejs callback example
This file contains hidden or 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
// 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