Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
kcenon::thread::cancellable_future< void > Class Reference

Specialization for void return type. More...

#include <cancellable_future.h>

Collaboration diagram for kcenon::thread::cancellable_future< void >:
Collaboration graph

Public Types

using value_type = void
 

Public Member Functions

 cancellable_future (std::future< void > future, cancellation_token token)
 
 ~cancellable_future ()=default
 
 cancellable_future (const cancellable_future &)=delete
 
cancellable_futureoperator= (const cancellable_future &)=delete
 
 cancellable_future (cancellable_future &&) noexcept=default
 
cancellable_futureoperator= (cancellable_future &&) noexcept=default
 
auto get () -> common::VoidResult
 
auto get_for (std::chrono::milliseconds timeout) -> common::Result< bool >
 
auto is_ready () const -> bool
 
auto is_cancelled () const -> bool
 
void cancel ()
 
auto valid () const -> bool
 
void wait () const
 
template<typename Rep , typename Period >
auto wait_for (const std::chrono::duration< Rep, Period > &timeout) const -> std::future_status
 
auto get_token () const -> cancellation_token
 

Private Attributes

std::future< void > future_
 
cancellation_token token_
 

Detailed Description

Specialization for void return type.

Definition at line 215 of file cancellable_future.h.

Member Typedef Documentation

◆ value_type

using kcenon::thread::cancellable_future< void >::value_type = void

Definition at line 217 of file cancellable_future.h.

Constructor & Destructor Documentation

◆ cancellable_future() [1/3]

kcenon::thread::cancellable_future< void >::cancellable_future ( std::future< void > future,
cancellation_token token )
inline

Definition at line 219 of file cancellable_future.h.

220 : future_(std::move(future))
221 , token_(std::move(token))
222 {}

◆ ~cancellable_future()

◆ cancellable_future() [2/3]

kcenon::thread::cancellable_future< void >::cancellable_future ( const cancellable_future< void > & )
delete

◆ cancellable_future() [3/3]

kcenon::thread::cancellable_future< void >::cancellable_future ( cancellable_future< void > && )
defaultnoexcept

Member Function Documentation

◆ cancel()

void kcenon::thread::cancellable_future< void >::cancel ( )
inline

Definition at line 273 of file cancellable_future.h.

273 {
274 token_.cancel();
275 }
void cancel()
Cancels the operation.

References kcenon::thread::cancellation_token::cancel(), and kcenon::thread::cancellable_future< R >::token_.

Here is the call graph for this function:

◆ get()

auto kcenon::thread::cancellable_future< void >::get ( ) -> common::VoidResult
inlinenodiscard

Definition at line 231 of file cancellable_future.h.

231 {
232 if (token_.is_cancelled()) {
234 }
235 try {
236 future_.get();
237 return common::ok();
238 } catch (const std::exception& e) {
240 } catch (...) {
241 return make_error_result(error_code::unknown_error, "Unknown exception in future");
242 }
243 }
bool is_cancelled() const
Checks if the token has been canceled.
common::VoidResult make_error_result(error_code code, const std::string &message="")
Create a common::VoidResult error from a thread::error_code.

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.

Here is the call graph for this function:

◆ get_for()

auto kcenon::thread::cancellable_future< void >::get_for ( std::chrono::milliseconds timeout) -> common::Result<bool>
inlinenodiscard

Definition at line 245 of file cancellable_future.h.

245 {
246 if (token_.is_cancelled()) {
248 }
249
250 auto status = future_.wait_for(timeout);
251 if (status == std::future_status::ready) {
252 try {
253 future_.get();
254 return common::Result<bool>::ok(true);
255 } catch (const std::exception& e) {
257 } catch (...) {
258 return make_error_result<bool>(error_code::unknown_error, "Unknown exception in future");
259 }
260 }
261 return common::Result<bool>::ok(false);
262 }

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.

Here is the call graph for this function:

◆ get_token()

auto kcenon::thread::cancellable_future< void >::get_token ( ) const -> cancellation_token
inlinenodiscard

Definition at line 292 of file cancellable_future.h.

292 {
293 return token_;
294 }

References kcenon::thread::cancellable_future< R >::token_.

◆ is_cancelled()

auto kcenon::thread::cancellable_future< void >::is_cancelled ( ) const -> bool
inlinenodiscard

Definition at line 269 of file cancellable_future.h.

269 {
270 return token_.is_cancelled();
271 }

References kcenon::thread::cancellation_token::is_cancelled(), and kcenon::thread::cancellable_future< R >::token_.

Here is the call graph for this function:

◆ is_ready()

auto kcenon::thread::cancellable_future< void >::is_ready ( ) const -> bool
inlinenodiscard

Definition at line 264 of file cancellable_future.h.

264 {
265 return future_.wait_for(std::chrono::seconds(0)) ==
266 std::future_status::ready;
267 }

References kcenon::thread::cancellable_future< R >::future_.

◆ operator=() [1/2]

cancellable_future & kcenon::thread::cancellable_future< void >::operator= ( cancellable_future< void > && )
defaultnoexcept

◆ operator=() [2/2]

cancellable_future & kcenon::thread::cancellable_future< void >::operator= ( const cancellable_future< void > & )
delete

◆ valid()

auto kcenon::thread::cancellable_future< void >::valid ( ) const -> bool
inlinenodiscard

Definition at line 277 of file cancellable_future.h.

277 {
278 return future_.valid();
279 }

References kcenon::thread::cancellable_future< R >::future_.

◆ wait()

void kcenon::thread::cancellable_future< void >::wait ( ) const
inline

Definition at line 281 of file cancellable_future.h.

281 {
282 future_.wait();
283 }

References kcenon::thread::cancellable_future< R >::future_.

◆ wait_for()

template<typename Rep , typename Period >
auto kcenon::thread::cancellable_future< void >::wait_for ( const std::chrono::duration< Rep, Period > & timeout) const -> std::future_status
inlinenodiscard

Definition at line 286 of file cancellable_future.h.

288 {
289 return future_.wait_for(timeout);
290 }

References kcenon::thread::cancellable_future< R >::future_.

Member Data Documentation

◆ future_

std::future<void> kcenon::thread::cancellable_future< void >::future_
mutableprivate

Definition at line 297 of file cancellable_future.h.

◆ token_

Definition at line 298 of file cancellable_future.h.


The documentation for this class was generated from the following file: