Async Class
Naveen Chawla
naveen.chwl at gmail.com
Sun Feb 18 09:11:18 UTC 2018
In the example, promise rejection can be handled with a try+catch inside
`initializeAsync()` itself. But we're deviating from the topic of "async
constructor", from which this is separate
On Sun, 18 Feb 2018, 2:37 pm Naveen Chawla, <naveen.chwl at gmail.com> wrote:
> There is no rule that says you must propagate every promise.
> `initializeAsync` doesn't return anything, so the constructor just kicks
> off the async process.
>
> On Sun, 18 Feb 2018, 2:02 pm T.J. Crowder, <
> tj.crowder at farsightsoftware.com> wrote:
>
>> On Sun, Feb 18, 2018 at 8:27 AM, Naveen Chawla <naveen.chwl at gmail.com>
>> wrote:
>> >
>> > Like this:
>> >
>> > ```js
>> > class MyObject{
>> > constructor(){
>> > initializeAsync();
>> > }
>> >
>> > async initializeAsync(){
>> > await doSomething();
>> > await doSomethingElse();
>> > //etc.
>> > }
>> > }
>> > ```
>>
>> That constructor breaks one of the main rules of promises: Either handle
>> the rejection, or propagate the promise.
>>
>> -- T.J. Crowder
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180218/48fde9ef/attachment.html>
More information about the es-discuss
mailing list