No, you can easily terminate a promise by saving a reference to its reject/resolve callbacks, and calling either of them.
On Wed, 2 Aug 2017 at 01:59 Domenic Denicola <[email protected]> wrote: > That is not why. > > > ------------------------------ > *From:* Jan-Ivar Bruaroey <[email protected]> > *Sent:* Aug 1, 2017 3:47 PM > *To:* [email protected] > > *Subject:* Re: Stream + async await > > Because a promise is not a control surface of the asynchronous action > fulfilling it; confuses owner with consumer. > https://stackoverflow.com/a/41417429/918910 > > .: Jan-Ivar :. > > On 7/31/17 7:35 AM, T.J. Crowder wrote: > > Related: https://esdiscuss.org/topic/how-about-awaiting-arrays > (particularly the discussion of `await.race`), since effectively you're > doing a race between a timeout and each chunk. Also relevant is the former > work on cancelling promises, now withdrawn. (Can anyone point me at *why* > it was withdrawn?) > > -- T.J. Crowder > > On Mon, Jul 31, 2017 at 6:10 AM, kai zhu <[email protected]> wrote: > >> the timeout handler will not work as advertised, e.g. what if io / db >> issues causes a network stream to intermittently respond in intervals far >> greater than 30000ms or not at all? >> >> > On Jul 31, 2017, at 7:26 AM, James Browning <[email protected]> >> wrote: >> > >> > It'll look something like this: >> > >> > ```javascript >> > >> > async function consumeReadableStream(stream) { >> > const start = Date.now() >> > for await (const chunk of stream) { >> > >> > /* Do whatever you want with the chunk here e,g, await other >> > async tasks with chunks >> > send them off to wherever, etc >> > */ >> > >> > if (Date.now() - start > 30000) { >> > throw new Error('30000 ms timeout') >> > } >> > } >> > /* Instead of callbackOnce the returned promise from this function >> > itself can be used */ >> > } >> > >> > ``` >> > _______________________________________________ >> > es-discuss mailing list >> > [email protected] >> > https://mail.mozilla.org/listinfo/es-discuss >> >> _______________________________________________ >> es-discuss mailing list >> [email protected] >> https://mail.mozilla.org/listinfo/es-discuss >> > > > > _______________________________________________ > es-discuss mailing > [email protected]https://mail.mozilla.org/listinfo/es-discuss > > > -- > .: Jan-Ivar :. > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

