Async Class
Naveen Chawla
naveen.chwl at gmail.com
Sun Feb 18 08:27:19 UTC 2018
Like this:
```js
class MyObject{
constructor(){
initializeAsync();
}
async initializeAsync(){
await doSomething();
await doSomethingElse();
//etc.
}
}
```
Of course if you wanted to await at the constructor call level (and await
inside the constructor itself), e.g.
```js
const myObject = await new MyObject();
```
...then of course you would need the "async constructor" feature, like
you've requested, but then `new MyObject()` would return a promise.
Personally I have no problem with this:
It suffers from the same bug-set than you would get if you converted a
synchronous function to an asynchronous one (i.e. the need to await).
On Sat, 17 Feb 2018 at 11:13 Dimitrian Nine <dimtimeforever at gmail.com>
wrote:
> "You can just call an async method from the constructor (without await) -
> and then let that async method handle all the asynchronicity."
>
> Not sure about it - how control? callback?
> I prefer async/await then.
>
> "I think async constructor would make more sense than async class"
>
> Maybe: i use it for class more for difference between class and async
> class was more visible.
> But yes in total idea about async constructor.
> Both variants work for me.
> What more useful - i dont sure...
> _______________________________________________
> 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/ba7e4928/attachment-0001.html>
More information about the es-discuss
mailing list