Seastar
High performance C++ framework for concurrent servers
|
A future has a stored value. Semantically, the value is a std::optional<std::variant<T, std::exception_ptr>>. The actual type of the value in the implementation is future_state<T>.
A future without an initial value can be created by first creating a promise and then calling promise::get_future. The promise also stores a future_state<T> in case promise::set_value is called before get_future.
In addition to the future_state<T>, the promise and the future point to each other and the pointers are updated when either is moved.
If a future is consumed by future::then before the future is ready, a continuation is dynamically allocated. The continuation also has a future_state<T>, but unlinke a future it is never moved.
After a future creates a continuation, the corresponding promise points to the newly allocated continuation. When promise::set_value is called, the continuation is ready and is scheduled.
A promise then consists of
A special case is when a future blocks inside a thread. In that case we still need a continuation, but that continuation doesn't need a future_state<T> since the original future still exists on the stack.
So the valid states for a promise are: