|
ORIGINAL
|
Represents a one-time asynchronous producer with result setting capability. More...
#include <async.h>

Public Member Functions | |
| promise (const promise &)=delete | |
| promise & | operator= (const promise &)=delete |
| promise (promise &&other) noexcept | |
| promise & | operator= (promise &&other) noexcept |
| promise ()=default | |
| Default constructor creates an invalid promise. | |
| promise (Callback &&c) | |
| Constructs a promise with a computation callback. | |
| future< TYPE > | getFuture () |
| Gets the future associated with this promise. | |
| bool | valid () const noexcept |
| Checks if the promise is still valid (can be executed or have function extracted) | |
| std::function< TYPE()> | function () |
| Extracts the computation function from the promise. | |
| void | run () |
| Executes the computation and sets the result in the associated future. | |
Represents a one-time asynchronous producer with result setting capability.
| TYPE | The result type of the computation |
| Callback | The type of the computation callback |
Provides the means to set the result of an asynchronous computation. A promise is a single-use object that can be either executed via run() or have its computation function extracted via function(). Once used, the promise becomes invalid and cannot be reused.
Key characteristics:
|
default |
Default constructor creates an invalid promise.
Creates a promise that is not associated with any computation. The resulting promise is invalid and cannot be used until assigned a valid promise.
|
explicit |
Constructs a promise with a computation callback.
| c | Callback that will produce the result when executed |
The promise takes ownership of the callback and becomes valid. The callback will be invoked exactly once - either by run() or through function().
| std::function< TYPE()> original::async::promise< TYPE, Callback >::function | ( | ) |
Extracts the computation function from the promise.
| sysError | if the promise is invalid (already used or default-constructed) |
After calling this method:
| original::async::future< TYPE > original::async::promise< TYPE, Callback >::getFuture | ( | ) |
Gets the future associated with this promise.
| Nothing | - can be called multiple times while the promise is valid |
| void original::async::promise< TYPE, Callback >::run | ( | ) |
Executes the computation and sets the result in the associated future.
| sysError | if the promise is invalid (already used or default-constructed) |
| Any | exception thrown by the computation function (captured in the future) |
After calling this method:
|
noexcept |
Checks if the promise is still valid (can be executed or have function extracted)
A promise becomes invalid after: