OnixS C++ FIX Engine 4.14.0
Users' manual and API documentation
Loading...
Searching...
No Matches
SharedFuture< T > Class Template Reference

#include <OnixS/FIXEngine/Threading/Future.h>

Public Member Functions

 SharedFuture () noexcept
 SharedFuture (const SharedFuture< T > &other) noexcept
SharedFuture< T > & operator= (const SharedFuture< T > &other) noexcept
 SharedFuture (SharedFuture< T > &&other) noexcept
FutureBase & operator= (SharedFuture< T > &&other) noexcept
Implementation::FutureGetReturn< T >::Type get () const
void swap (SharedFuture< T > &other) noexcept
void get () const
Public Member Functions inherited from FutureBase
bool valid () const noexcept
ONIXS_FIXENGINE_API bool isReady () const
ONIXS_FIXENGINE_API bool hasValue () const
ONIXS_FIXENGINE_API bool hasException () const
ONIXS_FIXENGINE_API std::exception_ptr getExceptionPtr () const
ONIXS_FIXENGINE_API FutureStatus::Enum wait (int timeoutInMs=InfiniteTimeout) const

Friends

class Implementation::FutureHelper
class Implementation::PromiseBase

Additional Inherited Members

Public Types inherited from FutureBase
enum  
Protected Member Functions inherited from FutureBase
 FutureBase ()
ONIXS_FIXENGINE_API FutureBase (const FutureBase &other) noexcept
ONIXS_FIXENGINE_API FutureBase & operator= (const FutureBase &other) noexcept
ONIXS_FIXENGINE_API FutureBase (FutureBase &&other) noexcept
ONIXS_FIXENGINE_API FutureBase & operator= (FutureBase &&other) noexcept
ONIXS_FIXENGINE_API FutureBase (const System::FutureSharedState *state) noexcept
ONIXS_FIXENGINE_API FutureBase (const System::FutureSharedState *state, moving_init_t) noexcept
ONIXS_FIXENGINE_API ~FutureBase () noexcept
ONIXS_FIXENGINE_API void swap (FutureBase &other) noexcept
ONIXS_FIXENGINE_API const FutureValue & getValue () const
ONIXS_FIXENGINE_API void getVoid () const

Detailed Description

template<typename T>
class OnixS::Threading::SharedFuture< T >

Represents a future result of an asynchronous operation - a result that will eventually appear in the Future after the processing is complete.

The class template Future provides a mechanism to access the result of asynchronous operations :

  • An asynchronous operation (e.g. created via Promise) can provide a Future object to the creator of that asynchronous operation (e.g. via the Promise::getFuture).
  • The creator of the asynchronous operation can then use a variety of methods to query, wait for, or extract a value from Future. These methods may block if the asynchronous operation has not yet provided a value.
  • When the asynchronous operation is ready to send a result to the creator, it can do so by modifying the shared state (e.g. via the Promise::setValue) that is linked to the creator's Future.

The Future is the synchronization object constructed around the receiving end of the Promise channel. It allows for the separation of the initiation of an operation and the act of waiting for its result.

The Future is copiable and multiple SharedFuture objects may refer to the same shared state.

Unlike the std::future, this implementation has an extended API, allowing you to query the state of SharedFuture. The internal implementation is lock-free; therefore, setting and polling states do not lead to blocking of threads and/or switching of an execution context.

Note
An access to the same shared state from multiple threads is safe if each thread does it through its own copy of a SharedFuture object.
See also
https://en.cppreference.com/cpp/thread/shared_future.

Definition at line 243 of file Future.h.

Constructor & Destructor Documentation

◆ SharedFuture() [1/3]

template<typename T>
SharedFuture ( )
inlinenoexcept

Definition at line 246 of file Future.h.

◆ SharedFuture() [2/3]

template<typename T>
SharedFuture ( const SharedFuture< T > & other)
inlinenoexcept

The copy constructor.

Definition at line 250 of file Future.h.

◆ SharedFuture() [3/3]

template<typename T>
SharedFuture ( SharedFuture< T > && other)
inlinenoexcept

Definition at line 260 of file Future.h.

Member Function Documentation

◆ get() [1/2]

void get ( ) const
inline

Definition at line 299 of file Future.h.

◆ get() [2/2]

template<typename T>
Implementation::FutureGetReturn< T >::Type get ( ) const
inline

Returns the result. If the result is not ready, the method will block. When completes, it either returns a value or throws an exception.

This method waits until the Future has a valid result and retrieves it. It effectively calls the wait() in order to wait for the result.

Exceptions
Ifan exception was stored in the shared state referenced by this Future (e.g. via a call to the Promise::setException()) then that exception will be thrown.

Definition at line 274 of file Future.h.

◆ operator=() [1/2]

template<typename T>
SharedFuture< T > & operator= ( const SharedFuture< T > & other)
inlinenoexcept

The copy assignment.

Definition at line 254 of file Future.h.

◆ operator=() [2/2]

template<typename T>
FutureBase & operator= ( SharedFuture< T > && other)
inlinenoexcept

Definition at line 263 of file Future.h.

◆ swap()

template<typename T>
void swap ( SharedFuture< T > & other)
inlinenoexcept

swaps two SharedFuture objects

Definition at line 280 of file Future.h.

◆ Implementation::FutureHelper

template<typename T>
friend class Implementation::FutureHelper
friend

Definition at line 294 of file Future.h.

◆ Implementation::PromiseBase

template<typename T>
friend class Implementation::PromiseBase
friend

Definition at line 295 of file Future.h.