Promise rejections don't resolve the argument

Axel Rauschmayer axel at rauschma.de
Sun Dec 28 13:40:00 PST 2014


Regular behavior is (you reject with a 

```js
Promise.resolve(3).then(console.log.bind(console)) // logs 3
Promise.reject(3).catch(console.log.bind(console)) // logs 3
```

`Promise.resolve()` only unwraps promises passed to it, because that is needed for chaining:

```js
asyncFunc1()
.then(result1 => asyncFunc2()) // (A)
.then(result2 => console.log(result2));
```

`then` in line (A) returns a promise that is resolved with what its callback returns. Because resolving unwraps, `asyncFunc2` can return a promise and `result2` will contain the result of resolving it (which is what you want for chaining).


> On 28 Dec 2014, at 13:44, raul mihaila <raul.mihaila at gmail.com> wrote:
> 
> Can somebody please provide a rationale for why promise reject functions don't resolve the argument, if the argument is a promise, before they pass it to the handlers, like promise resolve functions do?
> 
> Promise.resolve(Promise.reject(3)).catch(console.log.bind(console)) // logs 3
> Promise.reject(Promise.resolve(2)).catch(console.log.bind(console)) // logs a promise

-- 
Dr. Axel Rauschmayer
axel at rauschma.de
rauschma.de



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20141228/aebd60d6/attachment.html>


More information about the es-discuss mailing list