libosmscout
0.1
|
Future provides mechanism to access result of asynchronous computation. More...
#include <CancelableFuture.h>
Classes | |
class | FutureBreaker |
class | Promise |
struct | State |
Public Types | |
using | CancelCallback = std::function< void()> |
using | DoneCallback = std::function< void(T const &)> |
Public Member Functions | |
void | Cancel () |
Cancel the corresponding execution. More... | |
CancelableFuture (CancelableFuture &&)=default | |
CancelableFuture (const CancelableFuture &)=default | |
bool | IsCanceled () |
void | OnCancel (const CancelCallback &callback) |
Callback triggered when future is canceled. More... | |
void | OnComplete (const DoneCallback &callback) |
Callback triggered on future complete. More... | |
CancelableFuture & | operator= (CancelableFuture &&)=default |
CancelableFuture & | operator= (const CancelableFuture &)=default |
std::future< T > | StdFuture () |
std::optional< T > | Value () |
virtual | ~CancelableFuture ()=default |
Future provides mechanism to access result of asynchronous computation.
Instead of std::future, this one provides callbacks. So the consumer of the value doesn't need to be blocked.
T |
using osmscout::CancelableFuture< T >::CancelCallback = std::function<void()> |
using osmscout::CancelableFuture< T >::DoneCallback = std::function<void(T const&)> |
|
default |
|
default |
|
virtualdefault |
|
inline |
Cancel the corresponding execution.
Cancel callbacks are executed in context of caller.
References osmscout::CancelableFuture< T >::State::Cancel().
|
inline |
|
inline |
Callback triggered when future is canceled.
It is called from thread that is canceling the execution. When future is completed already, callback is called immediately in thread of caller.
callback |
References osmscout::CancelableFuture< T >::State::cancelCallbacks, osmscout::CancelableFuture< T >::State::canceled, osmscout::CancelableFuture< T >::State::mutex, and osmscout::CancelableFuture< T >::State::value.
Referenced by osmscout::CancelableFuture< T >::StdFuture().
|
inline |
Callback triggered on future complete.
When future is canceled, it is never called. It is called from thread of value producer. When future is completed already, callback is called immediately in thread of caller.
callback |
References osmscout::CancelableFuture< T >::State::callbacks, osmscout::CancelableFuture< T >::State::canceled, osmscout::CancelableFuture< T >::State::mutex, and osmscout::CancelableFuture< T >::State::value.
Referenced by osmscout::CancelableFuture< T >::StdFuture().
|
default |
|
default |
|
inline |
|
inline |