These examples demonstrate how to organize your asynchronous JavaScript code using the promises, reactive and flow-control patterns to avoid JavaScript callback hell.
fs.readFile(myDataFile, 'utf8', function(error, data) {
if (error) throw error;
fs.writeFile(myDataFile, data + ' callback 1', function(error) {
if (error) throw error;
fs.writeFile(myLogFile, data + ' callback 2', function(error) {
if (error) throw error;
console.log('Process has been finished!');
});
});
});
- ES6/2015 Promise constructor
- ES6/2015 Promise.all method
- ES6/2015 Promise.race method
- Async Module
- CO Module
- Async/Await
- Using async/await with Array.prototype.map()
- Comparing Callbacks, Promises and Async/Await in TypeScript
- How to use async/await to write better JavaScript
- Async/Await in JavaScript - What, Why and How - Fun Fun Function
- Promises Patterns
- Callback of heaven
- Callbacks vs Promises vs RxJs Observables vs async/await
- ES6 Promises
- Flow Control in Modern JS: Callbacks to Promises to Async/Await
- Hands-on with CO module
- kriskowal Q
- Learn about promises before you start using async/await
- Node Hero - Understanding Async Programming in Node.js
- Node.js Async Best Practice & Avoiding Callback Hell
- The async/await pitfalls
In case you have doubt why I'm not using semicolon is because I got inspiration from these talks: