Synchronous Code
posts = loadPostsSync(); // ... wait till posts are fetched // ... do something with posts doTheNextThing(); // Has to wait until posts load
Asynchronous Code
posts = loadPostsAsync(function(){ // ... wait till posts are fetched // ... do something with posts }); doTheNextThing(); // Doesn't have to wait until posts load
Most Async code You work with will be part of an API or library
- XMLHTtpRequest & Fetch
- jQuery Ajax, Axios, other HTTP libraries
- Node.js fs ( filesystem ) module
There are few ways to work with Async code
- Callbacks
- Promises
- Async / Await
Leave a Reply