# What are some example for await…of uses

**URL:** https://es.discourse.group/t/what-are-some-example-for-await-of-uses/1570
**Category:** Research
**Created:** [December 28, 2022, 12:27am UTC](https://es.discourse.group/t/what-are-some-example-for-await-of-uses/1570 "2022-12-28T00:27:44Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Sukima](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/sukima/32/963_2.png) [@Sukima](https://es.discourse.group/u/Sukima)
#### Post date: [December 28, 2022, 12:27am UTC](https://es.discourse.group/t/what-are-some-example-for-await-of-uses/1570/1 "2022-12-28T00:27:44Z")

</div>

I am really intrigued by the for await…of syntax. I think it has a lot of potential and am curious on examples of use. I’ve found a couple of uses so far:

- Hypermedia APIs needing to fetch one at a time as each request offers the URL for the next request. A for await…of and an async generator can do a series of fetch() requests saving the state of the next URL each time till the server exhausts the chain. [Example](https://tritarget.org/fiddles/#DwQgIg8gwgKgmgBQKIAIAWAXAtgGwHwBQwmuKOAhgHYDmAvAEQCml9hxj5AJm1oxuSgDGacgCcAznwYBVGADEAtAA5WRDAEsMORngByjAO4o56zp23AA9Bq06CRcYNHqADhhQYAni8YMsAe04AV21VFBRLACoUWljaFAApcgA3cgBlJ1d3OPjIywJw8nFPSkEUADMg0o1-SmjyvmEwcn4ACgBKFABvAvCUAzR1bRRWjFEgxk6evr7tdwAjQM8Y7t6Z8Jx1SgBrcQAubpRKRgAPDAOAckwMF33LSxx-UUYsBQArcVqAOkF-LEtyC51JYPrULigAL4AGjW62enyCokEjH2KAA2l0juReJcul1KNjGB0IRDwdDDgScSgLnjKUT2iSyQBdGHrSEAblhGz4KHhK3IBnImgqjTQrSuGBudweTxe70+lB+fwBQJBCouUNWbPCvAwaEClwQEDSMA1XL6i04ngOCTSEF0X3EYy21HU5U8rUtnnarPWEPanLZnnUjBwnF5KK+oMoHUD6wFQvcxyMCFEf3UklaohieBQkgwMHUvH8QQwWc1AFYAAxV9oB2EQ3qN8K9OZCEuUbIoKtx8pPFAJ4WtNuY+ElpEoyEofzlEUYJotcgdKawvvZ4c8seI5HT2dbifiFdstuhlacfyCIK8Ts-Z4tRhIbTXssXFwXets0NfDCnDBQWo-p2Kz7siXx0nGMznpez5fF6XyAj4lCcK0oYfn0zZ9G6IwANTYb8VTuLmFadPMd7bBBKBQVezAYLBSzwS4iHIVRMFOBwP6Pi8NHimgojvmhjZWI4zhuIQDheNohDhFEMRxCgUBpGksmxCgeS9EQlhOp4kn2FYaAcNwRBelJKCgAoCjKfEAASMAALIADKWSg5kmRpxkaSQ+BAA)
- Setting up long lived event dispatchers. Adding an event handler that triggers the next iteration. A for await…of can iterate each time an event is triggered. [Example](https://tritarget.org/#EventIterator)

In Node.js for…await of is often used as a convenient run-to-completion WritableStream which is better then the legacy `data` event listener pattern. This is because Readable and Duplex streams implement the `Symbol.asyncIterator` interface.

WebStreams, however, do not implement the `Symbol.asyncIterator` interface. I’d also be curious to see an implementation of a WriteableStream that exposes a `Symbol.asyncIterator`.

What other examples have you seen out there that use the for await…of syntax? _Especially in the browser._

---

<div class="post-metadata">

### Author: ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)
#### Post date: [December 28, 2022, 10:02am UTC](https://es.discourse.group/t/what-are-some-example-for-await-of-uses/1570/2 "2022-12-28T10:02:43Z")

</div>

The WhatWG spec says that SessionManager and Session implements AsyncIterator

[https://webidl.spec.whatwg.org/#idl-iterable](https://webidl.spec.whatwg.org/#idl-iterable)

> **[sessions.Session - Mozilla | MDN](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/sessions/Session)**
>
> The Session object represents a tab or window that the user has closed in the current browsing session.
