cesium-native  0.41.0
CesiumAsync::SharedFuture< T > Class Template Reference

A value that will be available in the future, as produced by AsyncSystem. Unlike Future, a SharedFuture allows multiple continuations to be attached, and allows SharedFuture::wait to be called multiple times. More...

#include <CesiumAsync/SharedFuture.h>

Public Member Functions

template<typename Func >
CesiumImpl::ContinuationFutureType_t< Func, T > thenInWorkerThread (Func &&f)
 Registers a continuation function to be invoked in a worker thread when this Future resolves. More...
 
template<typename Func >
CesiumImpl::ContinuationFutureType_t< Func, T > thenInMainThread (Func &&f)
 Registers a continuation function to be invoked in the main thread when this Future resolves. More...
 
template<typename Func >
CesiumImpl::ContinuationFutureType_t< Func, T > thenImmediately (Func &&f)
 Registers a continuation function to be invoked immediately in whichever thread causes the Future to be resolved. More...
 
template<typename Func >
CesiumImpl::ContinuationFutureType_t< Func, T > thenInThreadPool (const ThreadPool &threadPool, Func &&f)
 Registers a continuation function to be invoked in a thread pool when this Future resolves. More...
 
template<typename Func >
Future< T > catchInMainThread (Func &&f)
 Registers a continuation function to be invoked in the main thread when this Future rejects. More...
 
template<typename Func >
Future< T > catchImmediately (Func &&f)
 Registers a continuation function to be invoked immediately, and invalidates this Future. More...
 
template<typename... TPassThrough>
Future< std::tuple< TPassThrough..., T > > thenPassThrough (TPassThrough &&... values)
 Passes through one or more additional values to the next continuation. More...
 
template<typename U = T, std::enable_if_t< std::is_same_v< U, T >, int > = 0, std::enable_if_t<!std::is_same_v< U, void >, int > = 0>
const U & wait () const
 Waits for the future to resolve or reject and returns the result. More...
 
template<typename U = T, std::enable_if_t< std::is_same_v< U, T >, int > = 0, std::enable_if_t< std::is_same_v< U, void >, int > = 0>
void wait () const
 
waitInMainThread ()
 Waits for this future to resolve or reject in the main thread while also processing main-thread tasks. More...
 
bool isReady () const
 Determines if this future is already resolved or rejected. More...
 

Friends

class AsyncSystem
 
template<typename R >
struct CesiumImpl::ParameterizedTaskUnwrapper
 
struct CesiumImpl::TaskUnwrapper
 
template<typename R >
class Future
 

Detailed Description

template<typename T>
class CesiumAsync::SharedFuture< T >

A value that will be available in the future, as produced by AsyncSystem. Unlike Future, a SharedFuture allows multiple continuations to be attached, and allows SharedFuture::wait to be called multiple times.

Template Parameters
TThe type of the value.

Definition at line 31 of file SharedFuture.h.

Member Function Documentation

◆ catchImmediately()

template<typename T >
template<typename Func >
Future<T> CesiumAsync::SharedFuture< T >::catchImmediately ( Func &&  f)
inline

Registers a continuation function to be invoked immediately, and invalidates this Future.

When this Future is rejected, the continuation function will be invoked in whatever thread does the rejection. Similarly, if the Future is already rejected when catchImmediately is called, the continuation function will be invoked immediately before this method returns.

If the function itself returns a Future, the function will not be considered complete until that returned Future also resolves.

Any then continuations chained after this one will be invoked with the return value of the catch callback.

Template Parameters
FuncThe type of the function.
Parameters
fThe function.
Returns
A future that resolves after the supplied function completes.

Definition at line 184 of file SharedFuture.h.

◆ catchInMainThread()

template<typename T >
template<typename Func >
Future<T> CesiumAsync::SharedFuture< T >::catchInMainThread ( Func &&  f)
inline

Registers a continuation function to be invoked in the main thread when this Future rejects.

If this Future is rejected from the main thread, the continuation function will be invoked immediately rather than queued for later execution in the main thread. Similarly, if the Future is already rejected when catchInMainThread is called from the main thread, the continuation function will be invoked immediately before this method returns.

If the function itself returns a Future, the function will not be considered complete until that returned Future also resolves.

Any then continuations chained after this one will be invoked with the return value of the catch callback.

Template Parameters
FuncThe type of the function.
Parameters
fThe function.
Returns
A future that resolves after the supplied function completes.

Definition at line 159 of file SharedFuture.h.

◆ isReady()

template<typename T >
bool CesiumAsync::SharedFuture< T >::isReady ( ) const
inline

Determines if this future is already resolved or rejected.

If this method returns true, it is guaranteed that wait will not block but will instead immediately return a value or throw an exception.

Returns
True if the future is already resolved or rejected and wait will not block; otherwise, false.

Definition at line 270 of file SharedFuture.h.

◆ thenImmediately()

template<typename T >
template<typename Func >
CesiumImpl::ContinuationFutureType_t<Func, T> CesiumAsync::SharedFuture< T >::thenImmediately ( Func &&  f)
inline

Registers a continuation function to be invoked immediately in whichever thread causes the Future to be resolved.

If the Future is already resolved, the supplied function will be called immediately in the calling thread and this method will not return until that function does.

If the function itself returns a Future, the function will not be considered complete until that returned Future also resolves.

Template Parameters
FuncThe type of the function.
Parameters
fThe function.
Returns
A future that resolves after the supplied function completes.

Definition at line 101 of file SharedFuture.h.

◆ thenInMainThread()

template<typename T >
template<typename Func >
CesiumImpl::ContinuationFutureType_t<Func, T> CesiumAsync::SharedFuture< T >::thenInMainThread ( Func &&  f)
inline

Registers a continuation function to be invoked in the main thread when this Future resolves.

If this Future is resolved from the main thread, the continuation function will be invoked immediately rather than queued for later execution in the main thread. Similarly, if the Future is already resolved when thenInMainThread is called from the main thread, the continuation function will be invoked immediately before this method returns.

If the function itself returns a Future, the function will not be considered complete until that returned Future also resolves.

Template Parameters
FuncThe type of the function.
Parameters
fThe function.
Returns
A future that resolves after the supplied function completes.

Definition at line 78 of file SharedFuture.h.

◆ thenInThreadPool()

template<typename T >
template<typename Func >
CesiumImpl::ContinuationFutureType_t<Func, T> CesiumAsync::SharedFuture< T >::thenInThreadPool ( const ThreadPool threadPool,
Func &&  f 
)
inline

Registers a continuation function to be invoked in a thread pool when this Future resolves.

If the function itself returns a Future, the function will not be considered complete until that returned Future also resolves.

If this Future is resolved from a thread pool thread, the continuation function will be invoked immediately rather than in a separate task. Similarly, if the Future is already resolved when thenInThreadPool is called from a designated thread pool thread, the continuation function will be invoked immediately before this method returns.

Template Parameters
FuncThe type of the function.
Parameters
fThe function.
Returns
A future that resolves after the supplied function completes.

Definition at line 131 of file SharedFuture.h.

◆ thenInWorkerThread()

template<typename T >
template<typename Func >
CesiumImpl::ContinuationFutureType_t<Func, T> CesiumAsync::SharedFuture< T >::thenInWorkerThread ( Func &&  f)
inline

Registers a continuation function to be invoked in a worker thread when this Future resolves.

If the function itself returns a Future, the function will not be considered complete until that returned Future also resolves.

If this Future is resolved from a designated worker thread, the continuation function will be invoked immediately rather than in a separate task. Similarly, if the Future is already resolved when thenInWorkerThread is called from a designated worker thread, the continuation function will be invoked immediately before this method returns.

Template Parameters
FuncThe type of the function.
Parameters
fThe function.
Returns
A future that resolves after the supplied function completes.

Definition at line 52 of file SharedFuture.h.

◆ thenPassThrough()

template<typename T >
template<typename... TPassThrough>
Future<std::tuple<TPassThrough..., T> > CesiumAsync::SharedFuture< T >::thenPassThrough ( TPassThrough &&...  values)
inline

Passes through one or more additional values to the next continuation.

The next continuation will receive a tuple with each of the provided values, followed by the result of the current Future.

Template Parameters
TPassThroughThe types to pass through to the next continuation.
Parameters
valueThe values to pass through to the next continuation.
Returns
A new Future that resolves to a tuple with the pass-through values, followed by the result of the last Future.

Definition at line 204 of file SharedFuture.h.

◆ wait()

template<typename T >
template<typename U = T, std::enable_if_t< std::is_same_v< U, T >, int > = 0, std::enable_if_t<!std::is_same_v< U, void >, int > = 0>
const U& CesiumAsync::SharedFuture< T >::wait ( ) const
inline

Waits for the future to resolve or reject and returns the result.

This method must not be called from the main thread, the one that calls AsyncSystem::dispatchMainThreadTasks. Doing so can lead to a deadlock because the main thread tasks will never complete while this method is blocking the main thread.

To wait in the main thread, use waitInMainThread instead.

Returns
The value if the future resolves successfully.
Exceptions
Anexception if the future rejected.

Definition at line 229 of file SharedFuture.h.

◆ waitInMainThread()

template<typename T >
T CesiumAsync::SharedFuture< T >::waitInMainThread ( )
inline

Waits for this future to resolve or reject in the main thread while also processing main-thread tasks.

This method must be called from the main thread.

The function does not return until Future::isReady returns true. In the meantime, main-thread tasks are processed as necessary. This method does not spin wait; it suspends the calling thread by waiting on a condition variable when there is no work to do.

Returns
The value if the future resolves successfully.
Exceptions
Anexception if the future rejected.

Definition at line 255 of file SharedFuture.h.


The documentation for this class was generated from the following files: