Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
|
Corresponds to std::future. More...
#include <Future.h>
Public Member Functions | |
Future ()=default | |
Future (const Future &o)=delete | |
Future (Future &&)=default | |
Future & | operator= (Future &&other) |
~Future () | |
template<typename Callback > | |
PackagedTask< Callback > | Wrap (Callback &&callback) |
Make the future wait for the result of callback. More... | |
ResultType | Get () |
Move the result out of the future, and invalidate the future. More... | |
bool | IsReady () const |
bool | Valid () const |
void | Wait () |
void | CancelOrWait () |
Cancels the task, waiting if the task is currently started. More... | |
Protected Attributes | |
std::shared_ptr< FutureSharedStateDetail::Receiver< ResultType > > | m_Receiver |
Private Types | |
using | Status = FutureSharedStateDetail::Status |
Static Private Attributes | |
static constexpr bool | VoidResult = std::is_same_v<ResultType, void> |
Friends | |
template<typename T > | |
class | PackagedTask |
Corresponds to std::future.
Lightweight header / forward declarations for Future.
Unlike std::future, Future can request the cancellation of the task that would produce the result. This makes it more similar to Java's CancellableTask or C#'s Task. The name Future was kept over Task so it would be more familiar to C++ users, but this all should be revised once Concurrency TS wraps up.
Future is not thread-safe. Call it from a single thread or ensure synchronization externally.
The callback never runs after the Future
is destroyed. TODO:
Include this in your header files where possible.
|
private |
|
delete |
|
inline |
Cancels the task, waiting if the task is currently started.
Use this function over Cancel() if you need to ensure determinism (i.e. in the simulation).
|
inline |
Move the result out of the future, and invalidate the future.
If the future is not complete, calls Wait(). If the future is canceled, asserts.
|
inline |
|
inline |
|
inline |
|
inline |
PackagedTask< Callback > Future< ResultType >::Wrap | ( | Callback && | callback | ) |
Make the future wait for the result of callback.
|
protected |
|
staticconstexprprivate |