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

Isiah Meadows isiahmeadows at gmail.com
Thu Jan 12 21:08:08 UTC 2017


Look up the "revealing constructor pattern". There's a reason why only the
creator can resolve a promise imperatively.

On Thu, Jan 12, 2017, 09:22 Igor Baklan <io.baklan at gmail.com> wrote:

> 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).
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170112/9c422345/attachment.html>


More information about the es-discuss mailing list