This repository is a companion to a blog post that I wrote about implementing a Promise library. It contains the final source code for the library, a demonstration page, and branches to demonstrate the different steps of getting to the final solution.
You can see the finished library code here: promise.js
The demonstration is in index.html, you'll need to clone this repository and then host using something like python2's SimpleHTTPServer
module (eg. python -m SimpleHTTPServer
) or python3's http.server
module (eg. python3 -m http.server
). It needs to be hosted for Cross-Origin Resource Sharing (CORS) to request an external image from lorempixel.com
Look at the branches named step#
for the progression of getting to the final solution:
- step0: Initial setup of demo, Promise library is empty stub
- step1: Initial implementation, Promise library handles single .then() with success/failure handlers
- step2: Promise library can handle chaining .then(), adds .catch() convenience method
- step3: Promise library can handle .then() handlers returning Promises
- step4: Implement Promise.race() to resolve/reject with the first of a set of Promises to resolve/reject
- step5: Implement Promise.all() to resolve a set of Promises at the same time