A small, runnable JavaScript reference for promise fulfillment and rejection, Promise.all, Promise.race, and async/await.
- Fulfillment and rejection with
Errorobjects - Concurrent tasks with
Promise.all, including input-order results - Timed
Promise.raceexamples for both fulfillment and rejection - A concise
async/awaitexample - Simple runnable JavaScript without a framework
node index.jsPromise.allreturns results in the same order as its input, even when tasks finish in a different order.Promise.racesettles with whichever input settles first, whether it fulfills or rejects.Promise.racedoes not cancel the other tasks; their timers continue to run.
- Compare
Promise.allwithPromise.allSettledandPromise.any. - Add cancellation with
AbortControllerto a promise-based request. - Change the task delays and predict the output before running the file.
- Portfolio: https://www.ashishranjan.net/
- GitHub: https://github.com/a2rp
- CodePen: https://codepen.io/ash1198
- LinkedIn: https://www.linkedin.com/in/aashishranjan
- Facebook: https://www.facebook.com/theash.ashish/
- YouTube: https://www.youtube.com/@ashishranjan-ashz?sub_confirmation=1
- Email: ash.ranjan09@gmail.com
- Support: https://a2rp-donation-page.netlify.app/
- Buy Me a Coffee: https://buymeacoffee.com/a2rp
- Patreon: https://www.patreon.com/a2rp