Class that gets the output of a different thread executing in a thread safe manner. This class is similar to the std::shared_future
class of C++11.
More...
#include "nn/nlib/threading/Future.h"
Inherits nn::nlib::threading::detail::FutureBase< Derived >.
template<class R>
class nn::nlib::threading::Future< R >
Class that gets the output of a different thread executing in a thread safe manner. This class is similar to the std::shared_future
class of C++11.
- Template Parameters
-
R | The type of the value to get. You can also specify void . |
- Description
Future
can be associated with Promise
by using Promise<R>::GetFuture
or PackagedTask<T>::GetFuture
. Future
contains space shared with the function's execution thread. Future
provides a framework to safely get the result set by the function's execution thread.
- This class is implemented using internal conditional variables and shared pointers. A brief code sample is provided in the description of
PackagedTask
.
Definition at line 26 of file AsyncFileIo.h.
◆ Get() [1/2]
Calls Get(R* ptr)
after creating an object for the type that will be used internally as the value.
- Returns
- The result of
Future
.
- Description
- Note that the
R
constructor may throw an exception when using this function.
In addition, you cannot get the error that might occur when you act to get the value.
Definition at line 642 of file Future.h.
◆ Get() [2/2]
Waits until a result is acquired, and then gets the result.
- Parameters
-
[in,out] | ptr | Pointer where a value is set. |
- Returns
- 0 Returns whether a value has been set in
ptr
. All other values are an error value set by the thread.
- Description
- A
Get
function that does not take arguments may be used when Future<void>
.
Definition at line 649 of file Future.h.
◆ IsReady()
Returns whether a value has been set for Future
(whether Promise
set a value or an error).
- Returns
- Returns
true
if a value has been set to Future
.
Definition at line 668 of file Future.h.
◆ IsValid()
◆ MakeSharedFrom()
Shares a Future
so that it may be viewed.
- Parameters
-
- Returns
- Returns
0
on success.
- Description
Future
includes a view counter. You may use this function to wait for the same result from multiple threads.
- To prevent the proliferation of shared pointers, the
Future
class does not define a copy or assignment operator.
Definition at line 680 of file Future.h.
◆ Then()
template<class R>
template<class RNEXT >
Registers the process to continue (continuation) to this future.
- Template Parameters
-
RNEXT | Return value type of the continuation. |
- Parameters
-
[out] | next | Type of Future that corresponds to the continuation. |
[in] | cont | Function registered as a continuation. |
- Return values
-
0 | Success. |
EINVAL | Future is not associated with promise . |
ENOMEM | Not enough memory. |
Another | error may be returned from a lower layer. |
- Description
- In asynchronous programming, sometimes a new process is started and has data passed to it when an asynchronous process completes. You can wait for
Future
by using Then
to relate the continuing process to the asynchronous process.
- The use of
Then
makes it easier to write a process where the main thread receives the in-progress information of the subthread at appropriate points.
Definition at line 677 of file Future.h.
◆ WaitFor()
Waits for conditions that allow results to be acquired, for a specified amount of time.
- Parameters
-
[in] | span | Duration to wait for. |
- Return values
-
0 | Indicates that a result can be acquired. |
ETIMEDOUT | Indicates that a timeout has occurred. |
- Description
if (future.WaitFor(TimeSpan(0, 0, 10)) == 0) {
result = future.Get();
}
Definition at line 670 of file Future.h.
◆ WaitUntil()
Waits for conditions that allow results to be acquired, until the defined time.
- Parameters
-
[in] | datetime | Wait limit time. |
- Return values
-
0 | Indicates that a result can be acquired. |
ETIMEDOUT | Indicates that a timeout has occurred. |
Definition at line 673 of file Future.h.
The documentation for this class was generated from the following files: