-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Below is an underlying way to understand each of the coroutine types and what states they can be in.
class future {
std::variant<std::coroutine_handle, T> m_state;
};
class task {
std::coroutine_handle m_handle;
};For future, its either a coroutine or some value T. Once a future becomes a T, it is finished and no more work or resumption can occur.
For task, its expected to last as long as it needs to and if it completes, then its handle will becomes std::noop_coroutine_handle.
For generator, the generator can last for every or complete. Completion is determined when the handle becomes a std::noop_coroutine_handle. Generator provides APIs for accessing the value when its yielded. When a value is yielded, the value is returned and the internal state removes that value such that asking for a value again will yield an empty optional.
template<typename T>
class generator {
void resume();
bool has_value();
std::optional<T> get_value();
std::optional<T> get_next_value();
std::coroutine_handle m_handle;
std::optional<T> m_data;
};Metadata
Metadata
Assignees
Labels
No labels