This is already basically possible in userland, so to me, syntax seems
wholly unnecessary.

(re: Augusto)

Your helper could be simplified further:

```js
function promised(fn) {
    return (...args) => new Promise((resolve, reject) => {
        Reflect.apply(fn, {resolve, reject}, args)
    })
}
```

-----

Isiah Meadows
m...@isiahmeadows.com

Looking for web consulting? Or a new website?
Send me an email and we can get started.
www.isiahmeadows.com


On Thu, Apr 12, 2018 at 5:02 PM, Augusto Moura
<augusto.borg...@gmail.com> wrote:
> Also it can be already be implemented in user land with high orders
> functions:
>
> ``` js
> const sleep = promised(function (time) {
>   window.setTimeout(() => this.resolve(), time);
> });
> ```
>
> A simple implementation of a `promised` helper
>
> ``` js
> const promised = (fn) => (...args) => {
>   let target;
>   const promise = new Promise((resolve, reject) => {
>     target = { resolve, reject };
>   });
>   fn.apply(target, args);
>   return promise;
> }
> ```
>
>
> Em qui, 12 de abr de 2018 às 16:48, Mike Samuel <mikesam...@gmail.com>
> escreveu:
>>
>> This seems like it could be done with decorators per
>> https://github.com/tc39/proposal-decorators without introducing a new
>> keyword.
>>
>> @promises function sleep(...) {
>>   ...
>> }
>>
>>
>>
>> On Thu, Apr 12, 2018 at 12:07 PM, Luiz Felipe Frazão Gonçalves
>> <luizfelipefrazaogoncal...@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:
>>>
>>> promised function sleep(forHowLong) {
>>>   setTimeout(function() {
>>>     this.resolve(); // could even create a keyword like "resolve"
>>>
>>>     /**
>>>      * For reject:
>>>      *
>>>      * this.reject(Error('Some error'));
>>>      */
>>>   }, forHowLong);
>>> }
>>>
>>> Note that the hypothetical keyword "promised" before the function
>>> statement makes it act as a promise.
>>>
>>> Just a crazy idea I had. :)
>>>
>>>
>>> _______________________________________________
>>> es-discuss mailing list
>>> es-discuss@mozilla.org
>>> https://mail.mozilla.org/listinfo/es-discuss
>>>
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss@mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>
> --
> Augusto Moura
>
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to