Skip to content

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

License

Notifications You must be signed in to change notification settings

edysegura/js-asynchronous-and-flow-control

Repository files navigation

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:

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published