|
| AsyncSystem (const std::shared_ptr< ITaskProcessor > &pTaskProcessor) noexcept |
| Constructs a new instance. More...
|
|
template<typename T , typename Func > |
Future< T > | createFuture (Func &&f) const |
| Creates a new Future by immediately invoking a function and giving it the opportunity to resolve or reject a Promise. More...
|
|
template<typename T > |
Promise< T > | createPromise () const |
| Create a Promise that can be used at a later time to resolve or reject a Future. More...
|
|
template<typename Func > |
CesiumImpl::ContinuationFutureType_t< Func, void > | runInWorkerThread (Func &&f) const |
| Runs a function in a worker thread, returning a Future that resolves when the function completes. More...
|
|
template<typename Func > |
CesiumImpl::ContinuationFutureType_t< Func, void > | runInMainThread (Func &&f) const |
| Runs a function in the main thread, returning a Future that resolves when the function completes. More...
|
|
template<typename Func > |
CesiumImpl::ContinuationFutureType_t< Func, void > | runInThreadPool (const ThreadPool &threadPool, Func &&f) const |
| Runs a function in a thread pool, returning a Future that resolves when the function completes. More...
|
|
template<typename T > |
Future< AllValueType< T > > | all (std::vector< Future< T >> &&futures) const |
| Creates a Future that resolves when every Future in a vector resolves, and rejects when any Future in the vector rejects. More...
|
|
template<typename T > |
Future< AllValueType< T > > | all (std::vector< SharedFuture< T >> &&futures) const |
| Creates a Future that resolves when every Future in a vector resolves, and rejects when any Future in the vector rejects. More...
|
|
template<typename T > |
Future< T > | createResolvedFuture (T &&value) const |
| Creates a future that is already resolved. More...
|
|
Future< void > | createResolvedFuture () const |
| Creates a future that is already resolved and resolves to no value. More...
|
|
void | dispatchMainThreadTasks () |
| Runs all tasks that are currently queued for the main thread. More...
|
|
bool | dispatchOneMainThreadTask () |
| Runs a single waiting task that is currently queued for the main thread. If there are no tasks waiting, it returns immediately without running any tasks. More...
|
|
ThreadPool | createThreadPool (int32_t numberOfThreads) const |
| Creates a new thread pool that can be used to run continuations. More...
|
|
bool | operator== (const AsyncSystem &rhs) const noexcept |
|
bool | operator!= (const AsyncSystem &rhs) const noexcept |
|
A system for managing asynchronous requests and tasks.
Instances of this class may be safely and efficiently stored and passed around by value. However, it is essential that the last AsyncSystem instance be destroyed only after all continuations have run to completion. Otherwise, continuations may be scheduled using invalid scheduler instances, leading to a crash. Broadly, there are two ways to achieve this:
- Wait until all Futures complete before destroying the "owner" of the AsyncSystem.
- Make the AsyncSystem a global or static local in order to extend its lifetime all the way until program termination.
Definition at line 36 of file AsyncSystem.h.
Creates a Future that resolves when every Future in a vector resolves, and rejects when any Future in the vector rejects.
If the input Futures resolve to non-void values, the returned Future resolves to a vector of the values, in the same order as the input Futures. If the input Futures resolve to void, the returned Future resolves to void as well.
If any of the Futures rejects, the returned Future rejects as well. The exception included in the rejection will be from the first Future in the vector that rejects.
To get detailed rejection information from each of the Futures, attach a catchInMainThread
continuation prior to passing the list into all
.
- Template Parameters
-
T | The type that each Future resolves to. |
- Parameters
-
futures | The list of futures. |
- Returns
- A Future that resolves when all the given Futures resolve, and rejects when any Future in the vector rejects.
Definition at line 220 of file AsyncSystem.h.
Creates a Future that resolves when every Future in a vector resolves, and rejects when any Future in the vector rejects.
If the input SharedFutures resolve to non-void values, the returned Future resolves to a vector of the values, in the same order as the input SharedFutures. If the input SharedFutures resolve to void, the returned Future resolves to void as well.
If any of the SharedFutures rejects, the returned Future rejects as well. The exception included in the rejection will be from the first SharedFuture in the vector that rejects.
To get detailed rejection information from each of the SharedFutures, attach a catchInMainThread
continuation prior to passing the list into all
.
- Template Parameters
-
- Parameters
-
futures | The list of shared futures. |
- Returns
- A Future that resolves when all the given SharedFutures resolve, and rejects when any SharedFuture in the vector rejects.
Definition at line 248 of file AsyncSystem.h.
template<typename T , typename Func >
Future<T> CesiumAsync::AsyncSystem::createFuture |
( |
Func && |
f | ) |
const |
|
inline |
Creates a new Future by immediately invoking a function and giving it the opportunity to resolve or reject a Promise.
The Promise passed to the callback f
may be resolved or rejected asynchronously, even after the function has returned.
This method is very similar to AsyncSystem::createPromise, except that that method returns the Promise directly. The advantage of using this method instead is that it is more exception-safe. If the callback f
throws an exception, the Future
will be rejected automatically and the exception will not escape the callback.
- Template Parameters
-
T | The type that the Future resolves to. |
Func | The type of the callback function. |
- Parameters
-
f | The callback function to invoke immediately to create the Future. |
- Returns
- A Future that will resolve when the callback function resolves the supplied Promise.
Definition at line 65 of file AsyncSystem.h.
template<typename Func >
CesiumImpl::ContinuationFutureType_t<Func, void> CesiumAsync::AsyncSystem::runInMainThread |
( |
Func && |
f | ) |
const |
|
inline |
Runs a function in the main thread, returning a Future that resolves when the function completes.
If the function itself returns a Future
, the function will not be considered complete until that returned Future
also resolves.
If this method is called from the main thread, the callback will be invoked immediately and complete before this function returns.
- Template Parameters
-
Func | The type of the function. |
- Parameters
-
- Returns
- A future that resolves after the supplied function completes.
Definition at line 146 of file AsyncSystem.h.
template<typename Func >
CesiumImpl::ContinuationFutureType_t<Func, void> CesiumAsync::AsyncSystem::runInWorkerThread |
( |
Func && |
f | ) |
const |
|
inline |
Runs a function in a worker thread, returning a Future that resolves when the function completes.
If the function itself returns a Future
, the function will not be considered complete until that returned Future
also resolves.
If this method is called from a designated worker thread, the callback will be invoked immediately and complete before this function returns.
- Template Parameters
-
Func | The type of the function. |
- Parameters
-
- Returns
- A future that resolves after the supplied function completes.
Definition at line 116 of file AsyncSystem.h.