Remove iterator interface for folly::coro::AsyncGenerator
Summary: Simplified the interface for consuming an AsyncGenerator to now just have a single async next() method instead of an iterator-based API. The iterator-based API was added to integrate with the 'for co_await' syntax present in the Coroutines TS, however this syntax has been removed from C++20 to allow for future exploration of the AsyncRanges design-space. The `co_await gen.next()` expression produces an optional-like object that lets you query whether the result is a sentinel or contains a value. Old: ``` Task<void> consume(AsyncGenerator<T> gen) { for (auto it = co_await gen.begin(); it != gen.end(); co_await ++it) { use(*it); } } ``` New: ``` Task<void> consume(AsyncGenerator<T> gen) { while (auto item = co_await gen.next()) { use(*item); } } ``` Reviewed By: andriigrynenko, kirkshoop Differential Revision: D16586151 fbshipit-source-id: 4b0bf31ba9291d894a18e9553513eddee0cde33a
Showing
This diff is collapsed.
Please register or sign in to comment