|
Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
|
A future wrapper that supports cancellation. More...
#include <cancellable_future.h>

Public Types | |
| using | value_type = R |
Public Member Functions | |
| cancellable_future (std::future< R > future, cancellation_token token) | |
| Construct a cancellable_future. | |
| ~cancellable_future ()=default | |
| cancellable_future (const cancellable_future &)=delete | |
| cancellable_future & | operator= (const cancellable_future &)=delete |
| cancellable_future (cancellable_future &&) noexcept=default | |
| cancellable_future & | operator= (cancellable_future &&) noexcept=default |
| auto | get () -> common::Result< R > |
| Wait for and retrieve the result. | |
| auto | get_for (std::chrono::milliseconds timeout) -> common::Result< std::optional< R > > |
| Wait for the result with timeout. | |
| auto | is_ready () const -> bool |
| Check if the result is ready. | |
| auto | is_cancelled () const -> bool |
| Check if the operation was cancelled. | |
| void | cancel () |
| Request cancellation of the operation. | |
| auto | valid () const -> bool |
| Check if the future is valid. | |
| void | wait () const |
| Wait for the result to become ready. | |
| template<typename Rep , typename Period > | |
| auto | wait_for (const std::chrono::duration< Rep, Period > &timeout) const -> std::future_status |
| Wait for the result with timeout. | |
| auto | get_token () const -> cancellation_token |
| Get the cancellation token. | |
Private Attributes | |
| std::future< R > | future_ |
| cancellation_token | token_ |
A future wrapper that supports cancellation.
| R | The result type of the future |
This class wraps a std::future and a cancellation_token together, providing unified access to both the result and cancellation status.
Definition at line 56 of file cancellable_future.h.
| using kcenon::thread::cancellable_future< R >::value_type = R |
Definition at line 58 of file cancellable_future.h.
|
inline |
Construct a cancellable_future.
| future | The underlying std::future |
| token | The cancellation token for this operation |
Definition at line 66 of file cancellable_future.h.
|
default |
|
delete |
|
defaultnoexcept |
|
inline |
Request cancellation of the operation.
This signals the associated job to stop. The job must cooperatively check its cancellation token for this to have effect.
Definition at line 162 of file cancellable_future.h.
References kcenon::thread::cancellation_token::cancel(), and kcenon::thread::cancellable_future< R >::token_.

|
inlinenodiscard |
Wait for and retrieve the result.
This method blocks until the result is ready or the operation is cancelled.
Definition at line 91 of file cancellable_future.h.
References kcenon::thread::cancellation_token::is_cancelled(), kcenon::thread::job_execution_failed, kcenon::thread::make_error_result(), kcenon::thread::cancellable_future< R >::token_, and kcenon::thread::unknown_error.

|
inlinenodiscard |
Wait for the result with timeout.
| timeout | Maximum time to wait |
This method waits up to the specified timeout for the result. Returns std::nullopt in the Result if the timeout expires.
Definition at line 114 of file cancellable_future.h.
References kcenon::thread::cancellable_future< R >::future_, kcenon::thread::cancellation_token::is_cancelled(), kcenon::thread::job_execution_failed, kcenon::thread::make_error_result(), kcenon::thread::operation_canceled, kcenon::thread::cancellable_future< R >::token_, and kcenon::thread::unknown_error.

|
inlinenodiscard |
Get the cancellation token.
Definition at line 202 of file cancellable_future.h.
References kcenon::thread::cancellable_future< R >::token_.
|
inlinenodiscard |
Check if the operation was cancelled.
Definition at line 151 of file cancellable_future.h.
References kcenon::thread::cancellation_token::is_cancelled(), and kcenon::thread::cancellable_future< R >::token_.

|
inlinenodiscard |
Check if the result is ready.
Definition at line 141 of file cancellable_future.h.
References kcenon::thread::cancellable_future< R >::future_.
|
defaultnoexcept |
|
delete |
|
inlinenodiscard |
Check if the future is valid.
Definition at line 171 of file cancellable_future.h.
References kcenon::thread::cancellable_future< R >::future_.
|
inline |
Wait for the result to become ready.
Blocks until the result is available.
Definition at line 180 of file cancellable_future.h.
References kcenon::thread::cancellable_future< R >::future_.
|
inlinenodiscard |
Wait for the result with timeout.
| timeout | Maximum time to wait |
Definition at line 191 of file cancellable_future.h.
References kcenon::thread::cancellable_future< R >::future_.
|
mutableprivate |
Definition at line 207 of file cancellable_future.h.
Referenced by kcenon::thread::cancellable_future< R >::get_for(), kcenon::thread::cancellable_future< void >::get_for(), kcenon::thread::cancellable_future< R >::is_ready(), kcenon::thread::cancellable_future< void >::is_ready(), kcenon::thread::cancellable_future< R >::valid(), kcenon::thread::cancellable_future< void >::valid(), kcenon::thread::cancellable_future< R >::wait(), kcenon::thread::cancellable_future< void >::wait(), kcenon::thread::cancellable_future< R >::wait_for(), and kcenon::thread::cancellable_future< void >::wait_for().
|
private |
Definition at line 208 of file cancellable_future.h.
Referenced by kcenon::thread::cancellable_future< R >::cancel(), kcenon::thread::cancellable_future< void >::cancel(), kcenon::thread::cancellable_future< R >::get(), kcenon::thread::cancellable_future< void >::get(), kcenon::thread::cancellable_future< R >::get_for(), kcenon::thread::cancellable_future< void >::get_for(), kcenon::thread::cancellable_future< R >::get_token(), kcenon::thread::cancellable_future< void >::get_token(), kcenon::thread::cancellable_future< R >::is_cancelled(), and kcenon::thread::cancellable_future< void >::is_cancelled().