reusable_promise


A reusable_promise<T> allows a coroutine to return values to the caller multiple times. reusable_promise<T> satisfies the Reoccurring concept.

The coroutine key words available are co_yield (ARG), co_return (ARG) where T is constructible from ARG, and co_yield (std::nullopt_t), co_return (std::nullopt_t) in the case the promise cannot be fulfilled.


template<typename T>
class zab::reusable_promise

Public Types

enum State

Values:

enumerator kEmpty
enumerator kItem
enumerator kComplete
using returns = std::optional<T>

Public Functions

inline ~reusable_promise()
inline bool complete() const noexcept
inline bool value_ready() const noexcept
inline returns &&data() noexcept
inline void set_underlying(std::coroutine_handle<> _under) noexcept
inline void prepare() noexcept
inline void force_completion() noexcept
inline auto get_return_object() noexcept

Gets the coroutine handle from this.

Returns

The coroutine handle.

inline auto initial_suspend() noexcept

Always suspend execution of the promise. wait for it to be co_awaited.

Returns

A std::suspend_always

inline auto final_suspend() noexcept

Final suspension of Promise resumes the underlying coroutine that co_awaited the reusable_promise.

Returns

A structure for resuming the underlying coroutine.

template<typename ...Args>
inline void return_value(Args&&... _args) noexcept

Creates the promised object from some values.

One day they may support co_return x y z;

Parameters

_args – The arguments to construct T with.

Template Parameters

Args – The types of the arguments.

inline void return_value(std::optional<T> &&_move) noexcept

Construct the optional of T.

Parameters

_move – The optional to move.

inline void return_value(std::optional<T> &_move) noexcept

Construct the optional of T.

Parameters

_move – The optional to move.

template<typename ...Args>
inline auto yield_value(Args&&... _args) noexcept

yield some value to the underlying coroutine.

Parameters

_args – The arguments to construct T with.

Template Parameters

Args – The types of the arguments.

Returns

final suspend.

inline auto yield_value(std::optional<T> &&_move) noexcept

Construct the optional of T.

Parameters

_move – The optional to move.

inline auto yield_value(std::optional<T> &_move) noexcept

Construct the optional of T.

Parameters

_move – The optional to move.

inline void return_value(std::nullopt_t) noexcept

Returns a nullopt.

Parameters

<unnamed>[in] Unused.

inline auto yield_value(std::nullopt_t) noexcept

yield a nullopt.

Parameters

<unnamed>[in] Unused.

inline void unhandled_exception()

Public Members

std::coroutine_handle underlying_
returns data_
State state_ = kEmpty