|
idfxx 1.0.0
Modern C++23 components for ESP-IDF
|
Async completion token. More...
Public Member Functions | |
| future ()=default | |
| Constructs an invalid (detached) future. | |
| template<typename W > requires std::is_invocable_r_v<result<T>, W&, std::optional<std::chrono::milliseconds>> | |
| future (W waiter) | |
| Constructs a future from a waiter callable. | |
| template<typename W , typename D > requires std::is_invocable_r_v<result<T>, W&, std::optional<std::chrono::milliseconds>> && std::is_nothrow_invocable_r_v<bool, const D&> | |
| future (W waiter, D done_check) | |
| Constructs a future with an explicit non-blocking done-check. | |
| bool | valid () const noexcept |
| Returns whether this future is associated with an async operation. | |
| bool | done () const noexcept |
| Non-blocking check for whether the operation has completed. | |
| T | wait () const |
| Blocks until the operation completes. | |
| template<typename Rep , typename Period > | |
| T | wait_for (const std::chrono::duration< Rep, Period > &timeout) const |
| Blocks until the operation completes or the timeout expires. | |
| result< T > | try_wait () const |
| Blocks until the operation completes. | |
| template<typename Rep , typename Period > | |
| result< T > | try_wait_for (const std::chrono::duration< Rep, Period > &timeout) const |
| Blocks until the operation completes or the timeout expires. | |
Async completion token.
Provides a std::shared_future-like API for awaiting an asynchronous operation. Callers can block until completion (wait() / try_wait()), wait with a timeout (wait_for() / try_wait_for()), or poll for completion non-blockingly (done()).
A future is a lightweight, copyable handle: copies and moves are cheap, and it can be freely stored in containers. All copies share the same underlying operation, so a completion observed on one copy is visible on every other copy. Any resources held by the producer on behalf of the async operation are released automatically when the last copy is destroyed.
| T | The value type produced on successful completion. Use void for pure completion notifications. |
Definition at line 62 of file future.hpp.
|
default |
Constructs an invalid (detached) future.
|
inlineexplicit |
Constructs a future from a waiter callable.
Intended for producers exposing an async operation via future. The waiter is called to service wait() / try_wait() / try_wait_for() and must honour the timeout argument:
std::nullopt — wait indefinitely;std::chrono::milliseconds{0} — non-blocking check, returning immediately.The waiter returns result<T> — either the completed value or an error (typically idfxx::errc::timeout when the deadline expires).
With this constructor, done() is serviced by calling the waiter with a zero timeout. Prefer the two-argument constructor when a cheap, non-consuming completion check is available.
| W | Waiter callable type. |
| waiter | Waiter callable. |
Definition at line 94 of file future.hpp.
|
inline |
Constructs a future with an explicit non-blocking done-check.
Intended for producers that have a cheap, non-consuming way to check completion (e.g. an atomic flag). When supplied, done_check is called to service done() instead of the waiter, avoiding a spurious wait round-trip.
| W | Waiter callable type. |
| D | Done-check callable type (must be noexcept). |
| waiter | Waiter callable (see single-argument constructor). |
| done_check | Non-blocking, noexcept completion check returning true when the operation has completed. |
Definition at line 114 of file future.hpp.
|
noexcept |
Non-blocking check for whether the operation has completed.
true if the operation is complete; also true for an invalid future. false if the operation is still in progress. Definition at line 208 of file future.hpp.
Blocks until the operation completes.
Safe to call on an invalid future: returns a value-initialized value.
Definition at line 220 of file future.hpp.
Referenced by idfxx::future< T >::wait().
| result< T > idfxx::future< T >::try_wait_for | ( | const std::chrono::duration< Rep, Period > & | timeout | ) | const |
Blocks until the operation completes or the timeout expires.
| Rep | Duration arithmetic type. |
| Period | Duration period type. |
| timeout | Maximum time to wait for completion. |
idfxx::errc::timeout if the deadline expired). Definition at line 233 of file future.hpp.
References idfxx::timeout.
Referenced by idfxx::future< T >::wait_for().
|
inlinenoexcept |
Returns whether this future is associated with an async operation.
true if the future was constructed from a producer and has not been moved-from; false for a default-constructed or moved-from future. Definition at line 124 of file future.hpp.
|
inline |
Blocks until the operation completes.
Safe to call on an invalid future: returns a value-initialized value.
| std::system_error | on failure. |
Definition at line 145 of file future.hpp.
References idfxx::future< T >::try_wait(), and idfxx::unwrap().
Blocks until the operation completes or the timeout expires.
| Rep | Duration arithmetic type. |
| Period | Duration period type. |
| timeout | Maximum time to wait for completion. |
| std::system_error | on failure or timeout. |
Definition at line 160 of file future.hpp.
References idfxx::timeout, idfxx::future< T >::try_wait_for(), and idfxx::unwrap().