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

Class representing a promised future. Can only be instantiated via a Promise object. More...

#include <quantum_icoro_future.h>

Inheritance diagram for Bloomberg::quantum::Future< T >:
Bloomberg::quantum::IThreadFuture< T > Bloomberg::quantum::ICoroFuture< T > Bloomberg::quantum::IThreadFutureBase Bloomberg::quantum::ICoroFutureBase

Public Types

using Ptr = std::shared_ptr< Future< T > >
 
- Public Types inherited from Bloomberg::quantum::IThreadFuture< T >
using ContextTag = ThreadContextTag
 
using Ptr = std::shared_ptr< IThreadFuture< T > >
 
using Impl = Future< T >
 
- Public Types inherited from Bloomberg::quantum::IThreadFutureBase
using Ptr = std::shared_ptr< IThreadFutureBase >
 
- Public Types inherited from Bloomberg::quantum::ICoroFuture< T >
using ContextTag = CoroContextTag
 
using Ptr = std::shared_ptr< ICoroFuture< T > >
 
using Impl = Future< T >
 
- Public Types inherited from Bloomberg::quantum::ICoroFutureBase
using Ptr = std::shared_ptr< ICoroFutureBase >
 

Public Member Functions

 Future ()=default
 
bool valid () const final
 Determines if this future still has a shared state with the corresponding promise object. More...
 
void wait () const final
 Waits for the future value. More...
 
std::future_status waitFor (std::chrono::milliseconds timeMs) const final
 Waits for the future value up to a maximum 'timeMs' milliseconds. More...
 
template<class V = T>
NonBufferRetType< V > get ()
 
template<class V = T>
const NonBufferRetType< V > & getRef () const
 
template<class V = T>
BufferRetType< V > pull (bool &isBufferClosed)
 
void wait (ICoroSync::Ptr sync) const final
 Waits for the future value. More...
 
std::future_status waitFor (ICoroSync::Ptr sync, std::chrono::milliseconds timeMs) const final
 Waits for the future value up to a maximum 'timeMs' milliseconds. More...
 
template<class V = T>
NonBufferRetType< V > get (ICoroSync::Ptr sync)
 Get the future value. More...
 
template<class V = T>
const NonBufferRetType< V > & getRef (ICoroSync::Ptr sync) const
 Get a reference the future value. More...
 
template<class V = T>
BufferRetType< V > pull (ICoroSync::Ptr sync, bool &isBufferClosed)
 Pull a single value from the future buffer. More...
 
- Public Member Functions inherited from Bloomberg::quantum::IThreadFuture< T >
template<class V = T>
NonBufferRetType< V > get ()
 Get the future value. More...
 
template<class V = T>
const NonBufferRetType< V > & getRef () const
 Get a reference the future value. More...
 
template<class V = T>
BufferRetType< V > pull (bool &isBufferClosed)
 Pull a single value from the future buffer. More...
 
- Public Member Functions inherited from Bloomberg::quantum::IThreadFutureBase
virtual ~IThreadFutureBase ()=default
 Virtual destructor. More...
 
- Public Member Functions inherited from Bloomberg::quantum::ICoroFutureBase
virtual ~ICoroFutureBase ()=default
 Virtual destructor. More...
 

Static Public Member Functions

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

Friends

template<class F >
class Promise
 

Detailed Description

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

Class representing a promised future. Can only be instantiated via a Promise object.

Template Parameters
TType of value returned by the future object.
Note
See IThreadFuture and ICoroFuture interfaces for usage details. An instance of this class can only be obtained via a Promise object and cannot be created on its own.

Member Typedef Documentation

◆ Ptr

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

Constructor & Destructor Documentation

◆ Future()

template<class T>
Bloomberg::quantum::Future< T >::Future ( )
default

Member Function Documentation

◆ deleter()

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

◆ get() [1/2]

template<class T >
template<class V >
NonBufferRetType< V > Bloomberg::quantum::Future< T >::get ( )

◆ get() [2/2]

template<class T >
template<class V >
NonBufferRetType< V > Bloomberg::quantum::Future< T >::get ( ICoroSync::Ptr  sync)

Get the future value.

Parameters
[in]syncPointer to the coroutine synchronization object.
Returns
The future value.
Note
Blocks until the future is ready or until an exception is thrown. Once this function returns, the future becomes invalidated (i.e. cannot be read again)

Implements Bloomberg::quantum::ICoroFuture< T >.

◆ getRef() [1/2]

template<class T >
template<class V >
const NonBufferRetType< V > & Bloomberg::quantum::Future< T >::getRef ( ) const

◆ getRef() [2/2]

template<class T >
template<class V >
const NonBufferRetType< V > & Bloomberg::quantum::Future< T >::getRef ( ICoroSync::Ptr  sync) const

Get a reference the future value.

Parameters
[in]syncPointer to the coroutine synchronization object.
Returns
A reference to the future value.
Note
Blocks until the future is ready or until an exception is thrown. Contrary to get(), this function does not invalidate the future and as such may be read again.

Implements Bloomberg::quantum::ICoroFuture< T >.

◆ operator delete()

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

◆ operator new()

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

◆ pull() [1/2]

template<class T >
template<class V >
BufferRetType< V > Bloomberg::quantum::Future< T >::pull ( bool &  isBufferClosed)

◆ pull() [2/2]

template<class T >
template<class V >
BufferRetType< V > Bloomberg::quantum::Future< T >::pull ( ICoroSync::Ptr  sync,
bool &  isBufferClosed 
)

Pull a single value from the future buffer.

Template Parameters
BUFRepresents a class of type Buffer.
VThe type of value contained in Buffer.
Parameters
[in]syncPointer to the coroutine synchronization object.
[out]isBufferClosedIndicates if this buffer is closed and no more Pull operations are allowed on it.
Returns
The next value pulled out from the front of the buffer.
Note
Method available for buffered futures only. Blocks until one value is retrieved from the buffer.

Implements Bloomberg::quantum::ICoroFuture< T >.

◆ valid()

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

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

Returns
True if valid, false otherwise.

Implements Bloomberg::quantum::ICoroFutureBase.

◆ wait() [1/2]

template<class T >
void Bloomberg::quantum::Future< T >::wait ( ) const
finalvirtual

Waits for the future value.

Note
This method blocks until the future is ready or until an exception is thrown.

Implements Bloomberg::quantum::IThreadFutureBase.

◆ wait() [2/2]

template<class T >
void Bloomberg::quantum::Future< T >::wait ( ICoroSync::Ptr  sync) const
finalvirtual

Waits for the future value.

Parameters
[in]syncA pointer to a coroutine synchronization object.
Note
This method blocks until the future is ready or until an exception is thrown.

Implements Bloomberg::quantum::ICoroFutureBase.

◆ waitFor() [1/2]

template<class T >
std::future_status Bloomberg::quantum::Future< T >::waitFor ( std::chrono::milliseconds  timeMs) const
finalvirtual

Waits for the future value up to a maximum 'timeMs' milliseconds.

Parameters
[in]timeMsThe maximum amount of milliseconds to wait until the future value becomes ready.
Returns
'ready' if value was posted before duration expired or 'timeout' otherwise.
Note
Blocks until the value is ready, until 'timeMs' duration expires or until an exception is thrown.

Implements Bloomberg::quantum::IThreadFutureBase.

◆ waitFor() [2/2]

template<class T >
std::future_status Bloomberg::quantum::Future< T >::waitFor ( ICoroSync::Ptr  sync,
std::chrono::milliseconds  timeMs 
) const
finalvirtual

Waits for the future value up to a maximum 'timeMs' milliseconds.

Parameters
[in]syncA pointer to a coroutine synchronization object.
[in]timeMsThe maximum amount of milliseconds to wait until the future value becomes ready.
Returns
'ready' if value was posted before duration expired or 'timeout' otherwise.
Note
Blocks until the value is ready, until 'timeMs' duration expires or until an exception is thrown.

Implements Bloomberg::quantum::ICoroFutureBase.

Friends And Related Function Documentation

◆ Promise

template<class T>
template<class F >
friend class Promise
friend