EcmaScript Proposal - Promised functions
Tab Atkins Jr.
jackalmage at gmail.com
Thu Apr 12 16:19:48 UTC 2018
On Thu, Apr 12, 2018 at 9:07 AM, Luiz Felipe Frazão Gonçalves
<luizfelipefrazaogoncalves at gmail.com> wrote:
> One new proposal for EcmaScript.
>
> Promised Functions
>
> Like async/await, the promised functions would be preceded by a keyword. In
> the case, promised, it would change the default behavior of the function,
> making it behave as a promise.
>
> I will use as an example a classic sleep function:
>
> function sleep(forHowLong) {
> return new Promise((resolve, reject) => {
> setTimeout(function() {
> resolve();
>
> /**
> * For reject:
> *
> * reject(Error('Some error'));
> */
> }, forHowLong);
> });
> }
>
> I think to avoid the huge amount of callbacks, there should be a syntax
> similar to this:
Some of these callbacks aren't necessary:
function sleep(forHowLong) {
return new Promise(resolve=>setTimeout(resolve, forHowLong));
}
Tho even if you do use all the same callbacks, just formatting it
properly helps:
function sleep(forHowLong) {
return new Promise(resolve=>setTimeout(_=>resolve(), forHowLong));
}
~TJ
More information about the es-discuss
mailing list