Async iterator destructuring?

Isiah Meadows contact at
Fri Feb 7 23:50:05 UTC 2020

It might be useful on some occasions to destructure async iterators. For
the sake of example, I'm using `await [...]` as the syntax, but I'm by no
means married to it.

1. Collecting a Node stream into a buffer:

const await [...buffers] = someStream.setEncoding('buffer')
return Buffer.concat(buffers)

2. Collecting the first matching entry in a database scan:

// It's different for each database
const await [item] = db.scan({
    filter: {key: value},
    limit: 1,

It's not a common need, but it's useful either way, and it brings async
iterators and sync iterators closer to feature parity.

Isiah Meadows
contact at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list