Lely core libraries  2.2.5
lely::ev::Future< T, E > Class Template Reference

A future. More...

#include <future.hpp>

Public Types

using result_type = util::Result< T, E >
 The type of the result stored in the shared state.
 

Public Member Functions

 Future () noexcept=default
 Constructs future without (a reference to) a shared state. More...
 
 Future (const Future &other) noexcept
 Constructs a future with a reference to the shared state of other.
 
 Future (Future &&other) noexcept
 Moves the shared state of other to *this. More...
 
Futureoperator= (const Future &other) noexcept
 Abandons the shared state of *this as if by ~Future(), then creates a reference to the shared state of other. More...
 
Futureoperator= (Future &&other) noexcept
 Abandons the shared state of *this as if by ~Future(), then moves the shared state of other to *this. More...
 
 ~Future ()
 Abandons the shared state. More...
 
 operator bool () const noexcept
 Checks whether *this contains (a reference to) a shared state.
 
bool is_unique () const noexcept
 Checks whether *this contains a unique reference to its shared state. More...
 
bool is_ready () const noexcept
 Checks whether the future is ready, i.e., its associated promise has been satisfied and a result has been stored in the shared state. More...
 
result_typeget ()
 Returns the result of a ready future. More...
 
const result_typeget () const
 Returns the result of a ready future. More...
 
void submit (ev_task &task) noexcept
 
template<class F >
void submit (ev_exec_t *exec, F &&f)
 
bool cancel (ev_task &task) noexcept
 
::std::size_t cancel_all () noexcept
 
bool abort (ev_task &task) noexcept
 
::std::size_t abort_all () noexcept
 
template<class F >
AsyncTask< F, Future >::future_type then (ev_exec_t *exec, F &&f)
 Attaches a continuation function to a future and returns a new future which becomes ready once the continuation completes. More...
 

Detailed Description

template<class T, class E>
class lely::ev::Future< T, E >

A future.

See also
ev_future_t

Definition at line 50 of file future.hpp.

Constructor & Destructor Documentation

◆ Future() [1/2]

template<class T , class E >
lely::ev::Future< T, E >::Future ( )
defaultnoexcept

Constructs future without (a reference to) a shared state.

Postcondition
operator bool() returns false.

◆ Future() [2/2]

template<class T , class E >
lely::ev::Future< T, E >::Future ( Future< T, E > &&  other)
inlinenoexcept

Moves the shared state of other to *this.

Postcondition
other has no shared state (operator bool() returns false).

Definition at line 407 of file future.hpp.

◆ ~Future()

template<class T , class E >
lely::ev::Future< T, E >::~Future ( )
inline

Abandons the shared state.

If no references remain to the shared state, it is destroyed.

See also
ev_future_release()

Definition at line 447 of file future.hpp.

Member Function Documentation

◆ operator=() [1/2]

template<class T , class E >
Future& lely::ev::Future< T, E >::operator= ( const Future< T, E > &  other)
inlinenoexcept

Abandons the shared state of *this as if by ~Future(), then creates a reference to the shared state of other.

Returns
*this.

Definition at line 418 of file future.hpp.

◆ operator=() [2/2]

template<class T , class E >
Future& lely::ev::Future< T, E >::operator= ( Future< T, E > &&  other)
inlinenoexcept

Abandons the shared state of *this as if by ~Future(), then moves the shared state of other to *this.

Postcondition
other has no shared state (operator bool() returns false).
Returns
*this;

Definition at line 435 of file future.hpp.

◆ is_unique()

template<class T , class E >
bool lely::ev::Future< T, E >::is_unique ( ) const
inlinenoexcept

Checks whether *this contains a unique reference to its shared state.

Precondition
operator bool() returns true.
See also
ev_future_is_unique()

Definition at line 462 of file future.hpp.

◆ is_ready()

template<class T , class E >
bool lely::ev::Future< T, E >::is_ready ( ) const
inlinenoexcept

Checks whether the future is ready, i.e., its associated promise has been satisfied and a result has been stored in the shared state.

Precondition
operator bool() returns true.
See also
ev_future_is_ready()

Definition at line 475 of file future.hpp.

◆ get() [1/2]

template<class T , class E >
result_type& lely::ev::Future< T, E >::get ( )
inline

Returns the result of a ready future.

Returns
a reference to the result stored in the shared state.
Exceptions
lely::ev::future_not_readyif operator bool() or is_ready() returns false.
See also
ev_future_get()

Definition at line 490 of file future.hpp.

◆ get() [2/2]

template<class T , class E >
const result_type& lely::ev::Future< T, E >::get ( ) const
inline

Returns the result of a ready future.

Returns
a reference to the result stored in the shared state.
Exceptions
lely::ev::future_not_readyif operator bool() or is_ready() returns false.
See also
ev_future_get()

Definition at line 506 of file future.hpp.

◆ submit() [1/2]

template<class T , class E >
void lely::ev::Future< T, E >::submit ( ev_task task)
inlinenoexcept
See also
ev_future_submit()

Definition at line 513 of file future.hpp.

◆ submit() [2/2]

template<class T , class E >
template<class F >
void lely::ev::Future< T, E >::submit ( ev_exec_t exec,
F &&  f 
)
inline
See also
ev_future_submit()

Definition at line 520 of file future.hpp.

◆ cancel()

template<class T , class E >
bool lely::ev::Future< T, E >::cancel ( ev_task task)
inlinenoexcept
See also
ev_future_cancel()

Definition at line 526 of file future.hpp.

◆ cancel_all()

template<class T , class E >
::std::size_t lely::ev::Future< T, E >::cancel_all ( )
inlinenoexcept
See also
ev_future_cancel()

Definition at line 532 of file future.hpp.

◆ abort()

template<class T , class E >
bool lely::ev::Future< T, E >::abort ( ev_task task)
inlinenoexcept
See also
ev_future_abort()

Definition at line 538 of file future.hpp.

◆ abort_all()

template<class T , class E >
::std::size_t lely::ev::Future< T, E >::abort_all ( )
inlinenoexcept
See also
ev_future_abort()

Definition at line 544 of file future.hpp.

◆ then()

template<class T , class E >
template<class F >
AsyncTask<F, Future>::future_type lely::ev::Future< T, E >::then ( ev_exec_t exec,
F &&  f 
)
inline

Attaches a continuation function to a future and returns a new future which becomes ready once the continuation completes.

The continuation receives a single parameter: *this. The result of the continuation (or any exception thrown during invocation) is stored in the future, unless the continuation returns a future. In that case, the result of that future (as obtained by get().value()) is used instead. This is known as implicit unwrapping.

Definition at line 558 of file future.hpp.


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