QuantumLibrary
Bloomberg::quantum::Promise< T > Class Template Reference

Class representing a promised value. More...

#include <quantum_icoro_promise.h>

Inheritance diagram for Bloomberg::quantum::Promise< T >:
Bloomberg::quantum::IPromiseBase Bloomberg::quantum::IThreadPromise< Promise, T > Bloomberg::quantum::ICoroPromise< Promise, T > Bloomberg::quantum::ITerminate Bloomberg::quantum::Traits::DerivedFrom< Promise< T >, IThreadPromise< Promise, T >, IPromiseBase > Bloomberg::quantum::Traits::DerivedFrom< Promise< T >, ICoroPromise< Promise, T >, IPromiseBase >

Public Types

using Ptr = std::shared_ptr< Promise< T > >
 
- Public Types inherited from Bloomberg::quantum::IPromiseBase
using Ptr = std::shared_ptr< IPromiseBase >
 
- Public Types inherited from Bloomberg::quantum::IThreadPromise< Promise, T >
using ContextTag = ThreadContextTag
 
using Ptr = std::shared_ptr< IThreadPromise< Promise, T > >
 
using Impl = Promise< T >
 
- Public Types inherited from Bloomberg::quantum::ICoroPromise< Promise, T >
using ContextTag = CoroContextTag
 
using Ptr = std::shared_ptr< ICoroPromise< Promise, T > >
 
using Impl = Promise< T >
 

Public Member Functions

 Promise ()
 
 ~Promise ()
 
IThreadFutureBase::Ptr getIThreadFutureBase () const final
 Get a thread-compatible interface used to access the associated future. More...
 
ICoroFutureBase::Ptr getICoroFutureBase () const final
 Get a coroutine-compatible interface used to access the associated future. More...
 
ThreadFuturePtr< T > getIThreadFuture () const
 Get the associated thread future. More...
 
CoroFuturePtr< T > getICoroFuture () const
 Get the associated coroutine future. More...
 
void terminate () final
 Terminates the object. More...
 
bool valid () const final
 Determines if this promise still has a shared state with the corresponding future object. More...
 
int setException (std::exception_ptr ex) final
 Set an exception in this promise. More...
 
template<class V , class = NonBufferType<T,V>>
int set (V &&value)
 
template<class V , class = BufferType<T,V>>
void push (V &&value)
 
template<class V , class = NonBufferType<T,V>>
int set (ICoroSync::Ptr sync, V &&value)
 
template<class V , class = BufferType<T,V>>
void push (ICoroSync::Ptr sync, V &&value)
 
template<class V = T, class = BufferRetType<V>>
int closeBuffer ()
 
- Public Member Functions inherited from Bloomberg::quantum::ITerminate
virtual ~ITerminate ()=default
 Virtual destructor. This function is explicitly left empty. More...
 
- Public Member Functions inherited from Bloomberg::quantum::IThreadPromise< Promise, T >
 IThreadPromise (Impl *derived)
 Constructor. More...
 
int set (V &&value)
 Set the promised value. More...
 
void push (V &&value)
 Push a single value into the promise buffer. More...
 
int closeBuffer ()
 Close a promise buffer. More...
 
- Public Member Functions inherited from Bloomberg::quantum::Traits::DerivedFrom< Promise< T >, IThreadPromise< Promise, T >, IPromiseBase >
virtual ~DerivedFrom ()=default
 
 operator IPromiseBase * ()
 
 operator IPromiseBase & ()
 
- Public Member Functions inherited from Bloomberg::quantum::ICoroPromise< Promise, T >
 ICoroPromise (Impl *derived)
 Constructor. More...
 
int set (ICoroSync::Ptr sync, V &&value)
 Set the promised value. More...
 
void push (ICoroSync::Ptr sync, V &&value)
 Push a single value into the promise buffer. More...
 
int closeBuffer ()
 Close a promise buffer. More...
 
- Public Member Functions inherited from Bloomberg::quantum::Traits::DerivedFrom< Promise< T >, ICoroPromise< Promise, T >, IPromiseBase >
virtual ~DerivedFrom ()=default
 
 operator IPromiseBase * ()
 
 operator IPromiseBase & ()
 

Static Public Member Functions

static void * operator new (size_t size)
 
static void operator delete (void *p)
 
static void deleter (Promise< T > *p)
 

Detailed Description

template<class T>
class Bloomberg::quantum::Promise< T >

Class representing a promised value.

Template Parameters
TType of value returned by the promise.
Note
See IPromiseBase, IThreadPromise and ICoroPromise interfaces for usage details.

Member Typedef Documentation

◆ Ptr

template<class T>
using Bloomberg::quantum::Promise< T >::Ptr = std::shared_ptr<Promise<T> >

Constructor & Destructor Documentation

◆ Promise()

template<class T >
Bloomberg::quantum::Promise< T >::Promise ( )

◆ ~Promise()

template<class T>
Bloomberg::quantum::Promise< T >::~Promise ( )

Member Function Documentation

◆ closeBuffer()

template<class T >
template<class V , class >
int Bloomberg::quantum::Promise< T >::closeBuffer ( )

◆ deleter()

template<class T >
void Bloomberg::quantum::Promise< T >::deleter ( Promise< T > *  p)
static

◆ getICoroFuture()

template<class T >
CoroFuturePtr< T > Bloomberg::quantum::Promise< T >::getICoroFuture ( ) const
virtual

Get the associated coroutine future.

Returns
An interface to the associated future object sharing a common state.

Implements Bloomberg::quantum::ICoroPromise< Promise, T >.

◆ getICoroFutureBase()

template<class T >
ICoroFutureBase::Ptr Bloomberg::quantum::Promise< T >::getICoroFutureBase ( ) const
finalvirtual

Get a coroutine-compatible interface used to access the associated future.

Returns
An interface to the associated future.

Implements Bloomberg::quantum::IPromiseBase.

◆ getIThreadFuture()

template<class T >
ThreadFuturePtr< T > Bloomberg::quantum::Promise< T >::getIThreadFuture ( ) const
virtual

Get the associated thread future.

Returns
An interface to the associated future object sharing a common state.

Implements Bloomberg::quantum::IThreadPromise< Promise, T >.

◆ getIThreadFutureBase()

template<class T >
IThreadFutureBase::Ptr Bloomberg::quantum::Promise< T >::getIThreadFutureBase ( ) const
finalvirtual

Get a thread-compatible interface used to access the associated future.

Returns
An interface to the associated future.

Implements Bloomberg::quantum::IPromiseBase.

◆ operator delete()

template<class T >
void Bloomberg::quantum::Promise< T >::operator delete ( void *  p)
static

◆ operator new()

template<class T >
void * Bloomberg::quantum::Promise< T >::operator new ( size_t  size)
static

◆ push() [1/2]

template<class T >
template<class V , class >
void Bloomberg::quantum::Promise< T >::push ( V &&  value)

◆ push() [2/2]

template<class T >
template<class V , class >
void Bloomberg::quantum::Promise< T >::push ( ICoroSync::Ptr  sync,
V &&  value 
)

◆ set() [1/2]

template<class T >
template<class V , class >
int Bloomberg::quantum::Promise< T >::set ( V &&  value)

◆ set() [2/2]

template<class T >
template<class V , class >
int Bloomberg::quantum::Promise< T >::set ( ICoroSync::Ptr  sync,
V &&  value 
)

◆ setException()

template<class T >
int Bloomberg::quantum::Promise< T >::setException ( std::exception_ptr  ex)
finalvirtual

Set an exception in this promise.

When setting an exception inside a promise, any attempt to read a value from the associated future will re-throw this exception. Any threads or coroutines already blocked on this future will immediately unblock and re-throw.

Parameters
[in]exAn exception pointer which has been caught via std::current_exception.
Returns
0 on success

Implements Bloomberg::quantum::IPromiseBase.

◆ terminate()

template<class T >
void Bloomberg::quantum::Promise< T >::terminate ( )
finalvirtual

Terminates the object.

Note
This method should contain all logic necessary to properly cleanup this instance.

Implements Bloomberg::quantum::ITerminate.

◆ valid()

template<class T >
bool Bloomberg::quantum::Promise< T >::valid ( ) const
finalvirtual

Determines if this promise still has a shared state with the corresponding future object.

Returns
True if valid, false otherwise.

Implements Bloomberg::quantum::IPromiseBase.