Skip to content
RED SAG Skills
medium10 pts · first answer countsjavascriptasync-awaitgenerators

Reading pages with for await

An API returns results in pages. Which code reads all pages one after another from this async generator?

async function* pages() {
  let url = "/api/orders?page=1"
  while (url) {
    const r = await (await fetch(url)).json()
    yield r.items
    url = r.next
  }
}
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions