Callbacks
function asyncMethod(message, callback_function) {
setTimeOut( function() {
console.log(message);
callback_function();
}, 400)
}
asyncMethod('Connect to Database', function() {
}
Nested Callbacks
asyncMethod('Connect to Database', function() {
asyncMethod('Verify User Details', function() {
asyncMethod('Check Permissions', function() {
asyncMethod('Update User', function() {} )
})
})
})
Best Practices
Arguments should be (err, results)
Always 'return' when you want to exit
© 2020 Better Solutions Limited. All Rights Reserved. © 2020 Better Solutions Limited TopPrevNext