Stream + async await

kai zhu kaizhu256 at gmail.com
Mon Jul 31 05:10:47 UTC 2017


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 <thejamesernator at gmail.com> 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
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



More information about the es-discuss mailing list