Async Class
Naveen Chawla
naveen.chwl at gmail.com
Sun Feb 18 13:03:33 UTC 2018
I think `awaitNew MyObject()` would fit the thrust of your idea more. This
would allow `new MyObject()` to still be an instance of the object instead
of a promise, even if the constructor is async. It would dispatch the async
parts of the constructor to the background instead of awaiting it. e.g.:
```js
class MyObject {
async constructor(){
//sync stuff
await doAsyncStuff();
//etc.
}
}
const
myObjectWithOnlySyncStuffCompleted = new MyObject(), //Gets a new
instance but with only the "sync stuff" completed. Async stuff gets
dispatched to the background
myObjectWithAsyncStuffCompleted = awaitNew MyObject() //Gets a new
instance with everything (including async stuff) completed
;
```
However, I have no problem the 1st version (new MyObject() returning a
promise if the constructor is async). I think it's more consistent with how
functions work anyway. But `awaitNew` serves the same requirement while
ensuring `new MyObject()` is always an instance of `MyObject`.
On Sun, 18 Feb 2018 at 17:16 Dimitrian Nine <dimtimeforever at gmail.com>
wrote:
> "Long story short, introducing this feature would slow down new/
> Reflect.construct"
> "since this might suggest it returning a Promise, which it mustn't "
>
> Can it help: if async class constructor will be return Promise(obj) and i
> suggest before use newAsync for that practice?
>
> Slow... but how much?
> _______________________________________________
> 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/20180218/73fc357b/attachment.html>
More information about the es-discuss
mailing list