Stream + async await

James Browning thejamesernator at gmail.com
Sun Jul 30 23:26:48 UTC 2017


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 */
}

```


More information about the es-discuss mailing list