Design Patterns · Middle · Question 12 of 75
How does a generator help implement an Iterator for a paginated API?
- ✓Correct answer: It yields items one by one and requests the next page lazily
- 2It loads all pages in parallel in separate threads
- 3It caches API responses between page reloads
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.