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.c...@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.crow...@farsightsoftware.com> wrote: > >> On Sun, Feb 18, 2018 at 8:27 AM, Naveen Chawla <naveen.c...@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 >> >
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss