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

A promise. 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

 Promise ()
 Constructs a promise with (a reference to) an empty shared state. More...
 
 Promise (const Promise &other) noexcept
 Constructs a promise with a reference to the shared state of other.
 
 Promise (Promise &&other) noexcept
 Moves the shared state of other to *this. More...
 
Promiseoperator= (const Promise &other) noexcept
 Abandons the shared state of *this as if by ~Promise(), then creates a reference to the shared state of other. More...
 
Promiseoperator= (Promise &&other) noexcept
 Abandons the shared state of *this as if by ~Promise(), then moves the shared state of other to *this. More...
 
 ~Promise ()
 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...
 
template<class U >
bool set (U &&u)
 Satisfies a promise, if it was not aready satisfied, and stores the specified value as the result in the shared state. More...
 
Future< T, E > get_future () const noexcept
 Returns a lely::ev::Future with (a reference to) the same shared state as *this. More...
 

Detailed Description

template<class T, class E = ::std::error_code>
class lely::ev::Promise< T, E >

A promise.

T and E should be nothrow default-constructible. Any exceptions thrown during the default construction of the shared state will result in a call to std::terminate().

See also
ev_promise_t

Definition at line 60 of file future.hpp.

Constructor & Destructor Documentation

◆ Promise() [1/2]

template<class T , class E = ::std::error_code>
lely::ev::Promise< T, E >::Promise ( )
inline

Constructs a promise with (a reference to) an empty shared state.

See also
ev_promise_create()

Definition at line 70 of file future.hpp.

◆ Promise() [2/2]

template<class T , class E = ::std::error_code>
lely::ev::Promise< T, E >::Promise ( Promise< 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 94 of file future.hpp.

◆ ~Promise()

template<class T , class E = ::std::error_code>
lely::ev::Promise< T, E >::~Promise ( )
inline

Abandons the shared state.

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

See also
ev_promise_release()

Definition at line 134 of file future.hpp.

Member Function Documentation

◆ operator=() [1/2]

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

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

Returns
*this.

Definition at line 105 of file future.hpp.

◆ operator=() [2/2]

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

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

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

Definition at line 122 of file future.hpp.

◆ is_unique()

template<class T , class E = ::std::error_code>
bool lely::ev::Promise< 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_promise_is_unique()

Definition at line 149 of file future.hpp.

◆ set()

template<class T , class E = ::std::error_code>
template<class U >
bool lely::ev::Promise< T, E >::set ( U &&  u)
inline

Satisfies a promise, if it was not aready satisfied, and stores the specified value as the result in the shared state.

Precondition
operator bool() returns true.
Returns
true if the promise is successfully satisfied, and false if it was already satisfied.
See also
ev_promise_set()

Definition at line 166 of file future.hpp.

◆ get_future()

template<class T , class E = ::std::error_code>
Future<T, E> lely::ev::Promise< T, E >::get_future ( ) const
inlinenoexcept

Returns a lely::ev::Future with (a reference to) the same shared state as *this.

Precondition
operator bool() returns true.

Definition at line 188 of file future.hpp.


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