Async iterator destructuring?

Bruno Macabeus bruno.macabeus at gmail.com
Fri Feb 7 23:53:56 UTC 2020


But is it not enough to do that?

```js
const [item] = await db.scan({
  ...
```

On Fri, 7 Feb 2020 at 23:50, Isiah Meadows <contact at isiahmeadows.com> wrote:

> 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:
>
> ```js
> const await [...buffers] = someStream.setEncoding('buffer')
> return Buffer.concat(buffers)
> ```
>
> 2. Collecting the first matching entry in a database scan:
>
> ```js
> // 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 isiahmeadows.com
> www.isiahmeadows.com
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20200207/6dcd0dc1/attachment.html>


More information about the es-discuss mailing list