GitHunt
ED

edysegura/js-asynchronous-and-flow-control

Simple examples in JavaScript to demonstrate asynchronous code and flow-control patterns

JavaScript Asynchronous and Flow-control

These examples demonstrate how to organize your asynchronous JavaScript code using the promises, reactive and flow-control patterns to avoid JavaScript callback hell.

JavaScript Asynchronous

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!');
    });
  });
});

Examples

References


In case you have doubt why I'm not using semicolon is because I got inspiration from these talks:

Languages

JavaScript100.0%

Contributors

MIT License
Created February 22, 2017
Updated January 18, 2023