Design Patterns · Middle · Question 12 of 75

How does a generator help implement an Iterator for a paginated API?

Explanation

An async generator hides cursors and page numbers: the consumer writes for await (const item of allItems()) and can stop at any time without loading anything extra. Traversal logic is separated from processing logic.

Further reading

Problem with a question

Design Patterns · Middle · question 12

Test yourself

Take the Design Patterns · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz