promise Class

 

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

Describes an asynchronous provider.

template <class Ty>
class promise;

Public Constructors

NameDescription
promise::promise ConstructorConstructs a promise object.

Public Methods

NameDescription
promise::get_future MethodReturns a future associated with this promise.
promise::set_exception MethodAtomically sets the result of this promise to indicate an exception.
promise::set_exception_at_thread_exit MethodAtomically sets the result of this promise to indicate an exception, and delivers the notification only after all thread-local objects in the current thread have been destroyed (usually at thread exit).
promise::set_value MethodAtomically sets the result of this promise to indicate a value.
promise::set_value_at_thread_exit MethodAtomically sets the result of this promise to indicate a value, and delivers the notification only after all thread-local objects in the current thread have been destroyed (usually at thread exit).
promise::swap MethodExchanges the associated asynchronous state of this promise with that of a specified promise object.

Public Operators

NameDescription
promise::operator=Assignment of the shared state of this promise object.

promise

Header: future

Namespace: std

Returns a future object that has the same associated asynchronous state as this promise.

future<Ty> get_future();

Remarks

If the promise object is empty, this method throws a future_error that has an error_code of no_state.

If this method has already been called for a promise object that has the same associated asynchronous state, the method throws a future_error that has an error_code of future_already_retrieved.

Transfers the associated asynchronous state from a specified promise object.

promise& operator=(promise&& Other) noexcept;

Parameters

Other
A promise object.

Return Value

*this

Remarks

This operator transfers the associated asynchronous state from Other. After the transfer, Other is empty.

Constructs a promise object.

promise();

template <class Alloc>
promise(
    allocator_arg_t,
 const Alloc& Al);

promise(
    promise&& Other) noexcept;

Parameters

Al
A memory allocator. See <allocators> for more information.

Other
A promise object.

Remarks

The first constructor constructs an emptypromise object.

The second constructor constructs an empty promise object and uses Al for memory allocation.

The third constructor constructs a promise object and transfers the associated asynchronous state from Other, and leaves Other empty.

Atomically stores an exception as the result of this promise object and sets the associated asynchronous state to ready.

void set_exception(exception_ptr Exc);

Parameters

Exc
An exception_ptr that's stored by this method as the exception result.

Remarks

If the promise object has no associated asynchronous state, this method throws a future_error that has an error code of no_state.

If set_exception, set_exception_at_thread_exit, set_value, or set_value_at_thread_exit has already been called for a promise object that has the same associated asynchronous state, this method throws a future_error that has an error code of promise_already_satisfied.

As a result of this method, any threads that are blocked on the associated asynchronous state become unblocked.

Atomically sets the result of this promise to indicate an exception, delivering the notification only after all thread-local objects in the current thread have been destroyed (usually at thread exit).

void set_exception_at_thread_exit(exception_ptr Exc);

Parameters

Exc
An exception_ptr that's stored by this method as the exception result.

Remarks

If the promise object has no associated asynchronous state, this method throws a future_error that has an error code of no_state.

If set_exception, set_exception_at_thread_exit, set_value, or set_value_at_thread_exit has already been called for a promise object that has the same associated asynchronous state, this method throws a future_error that has an error code of promise_already_satisfied.

In contrast to set_exception, this method does not set the associated asynchronous state to ready until after all thread-local objects in the current thread have been destroyed. Typically, threads that are blocked on the associated asynchronous state are not unblocked until the current thread exits.

Atomically stores a value as the result of this promise object and sets the associated asynchronous state to ready.

void promise::set_value(const Ty& Val);

void promise::set_value(Ty&& Val);

void promise<Ty&>::set_value(Ty& Val);

void promise<void>::set_value();

Parameters

Val
The value to be stored as the result.

Remarks

If the promise object has no associated asynchronous state, this method throws a future_error that has an error code of no_state.

If set_exception, set_exception_at_thread_exit, set_value, or set_value_at_thread_exit has already been called for a promise object that has the same associated asynchronous state, this method throws a future_error that has an error code of promise_already_satisfied.

As a result of this method, any threads that are blocked on the associated asynchronous state become unblocked.

The first method also throws any exception that is thrown when Val is copied into the associated asynchronous state. In this situation, the associated asynchronous state is not set to ready.

The second method also throws any exception that is thrown when Val is moved into the associated asynchronous state. In this situation, the associated asynchronous state is not set to ready.

For the partial specialization promise<Ty&>, the stored value is in effect a reference to Val.

For the specialization promise<void>, no stored value exists.

Atomically stores a value as the result of this promise object.

void promise::set_value_at_thread_exit(const Ty& Val);

void promise::set_value_at_thread_exit(Ty&& Val);

void promise<Ty&>::set_value_at_thread_exit(Ty& Val);

void promise<void>::set_value_at_thread_exit();

Parameters

Val
The value to be stored as the result.

Remarks

If the promise object has no associated asynchronous state, this method throws a future_error that has an error code of no_state.

If set_exception, set_exception_at_thread_exit, set_value, or set_value_at_thread_exit has already been called for a promise object that has the same associated asynchronous state, this method throws a future_error that has an error code of promise_already_satisfied.

In contrast to set_value, the associated asynchronous state is not set to ready until after all thread-local objects in the current thread have been destroyed. Typically, threads that are blocked on the associated asynchronous state are not unblocked until the current thread exits.

The first method also throws any exception that is thrown when Val is copied into the associated asynchronous state.

The second method also throws any exception that is thrown when Val is moved into the associated asynchronous state.

For the partial specialization promise<Ty&>, the stored value is effectively a reference to Val.

For the specialization promise<void>, no stored value exists.

Exchanges the associated asynchronous state of this promise object with that of a specified object.

void swap(promise& Other) noexcept;

Parameters

Other
A promise object.

Header Files Reference

Show: