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 <[email protected]> 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 > [email protected] > https://mail.mozilla.org/listinfo/es-discuss >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

