A Promise is an object that represents a (potential value) over time. A replacement for callbacks. Your job is to implement the Promise object. Here are the requirements:
- The Promise constructor takes a function with two arguments: new Promise((resolve, reject) => { ... })
- Calling the
resolvefunction inside of the handler will resolve the promise (i.e. success). You can call resolve with a single argument, which will be passed to.then(). - Calling the
rejectfunction will reject it (i.e. error). You should always call reject with an Error instance, which will be passed to.then().
- Calling the
- A Promise has three states, it starts at "pending" and can mutate only once to either "resolved" or "rejected".
- A Promise object has a
.then()method which accepts two functions, the first will call if it's resolved, and the second if it rejects.