Interesting idea, though I feel that this is too similar to async functions. 

What would be useful would some standard way of "awaiting" functions that require callbacks. Sort of like bluebird's Promise.fromCallback. Maybe 

```js
await.fromCallback fn()
```

Which can only be used by a function call and the postpends the parameters with a suitable callback function 

Sebastian Malton

From: luizfelipefrazaogoncal...@gmail.com
Sent: April 12, 2018 12:07 PM
To: es-discuss@mozilla.org
Subject: EcmaScript Proposal - Promised functions

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

Reply via email to