Introduction of promise.return() and promise.throw() similar to generator.return() and generator.throw()

Igor Baklan io.baklan at gmail.com
Thu Jan 12 14:22:04 UTC 2017


Introduction of promise.return() and promise.throw() similar to
generator.return() and generator.throw() can be helpful

Assuming analogy in tuples ([``function*``](https://
developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/
Statements/function*), [``yield``](https://developer.
mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/yield),
[``Generator.prototype.return()``](https://developer.
mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_
Objects/Generator/return), [``Generator.prototype.throw()``](
https://developer.mozilla.org/en-US/docs/Web/JavaScript/
Reference/Global_Objects/Generator/throw) ) and ([``async function``](
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/
Operators/async_function), [``await``](https://developer.
mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await),
``?Promise.prototype.return()``, ``?Promise.prototype.throw()``), it would
be good to have ``Promise.prototype.return()`` and
``Promise.prototype.throw()`` which in case of ``async``/``await`` function
should just "inject" some [``return``](https://developer.mozilla.org/en-US/
docs/Web/JavaScript/Reference/Statements/return)/[``throw``]
(https://developer.mozilla.org/en-US/docs/Web/JavaScript/
Reference/Statements/throw
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return)/%5Bthrow%5D(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/throw>)
action in place of pending ``await`` statement.

While for ``.then``-like promises it should just force promise to abnormal
completion (with provided result) without calling callbacks provided in
.``then``/.``catch`` methods (if they was not yet called before, at the
time of "abruption" attempt).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170112/99894aea/attachment.html>


More information about the es-discuss mailing list