Async Class

Naveen Chawla naveen.chwl at
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.:

class MyObject {
    async constructor(){
        //sync stuff
        await doAsyncStuff();

    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>

> "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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list