QuantumLibrary
Bloomberg::quantum::Context< RET > Class Template Reference

Concrete class representing a coroutine or a thread context. More...

#include <quantum_icoro_context.h>

Inheritance diagram for Bloomberg::quantum::Context< RET >:
Bloomberg::quantum::IThreadContext< RET > Bloomberg::quantum::ICoroContext< RET > Bloomberg::quantum::ITaskAccessor Bloomberg::quantum::IThreadContextBase Bloomberg::quantum::ICoroContextBase Bloomberg::quantum::ITerminate Bloomberg::quantum::IContextBase Bloomberg::quantum::IContextBase Bloomberg::quantum::ICoroSync

Public Types

using Ptr = std::shared_ptr< Context< RET > >
 
using ThreadCtx = IThreadContext< RET >
 
using CoroCtx = ICoroContext< RET >
 
- Public Types inherited from Bloomberg::quantum::IThreadContext< RET >
using ContextTag = ThreadContextTag
 
using Ptr = std::shared_ptr< IThreadContext< RET > >
 
using Impl = Context< RET >
 
- Public Types inherited from Bloomberg::quantum::IThreadContextBase
using Ptr = std::shared_ptr< IThreadContextBase >
 
- Public Types inherited from Bloomberg::quantum::IContextBase
using Ptr = std::shared_ptr< IContextBase >
 
- Public Types inherited from Bloomberg::quantum::ICoroContext< RET >
using ContextTag = CoroContextTag
 
using Ptr = std::shared_ptr< ICoroContext< RET > >
 
using Impl = Context< RET >
 
- Public Types inherited from Bloomberg::quantum::ICoroContextBase
using Ptr = std::shared_ptr< ICoroContextBase >
 
- Public Types inherited from Bloomberg::quantum::ICoroSync
using Ptr = std::shared_ptr< ICoroSync >
 
- Public Types inherited from Bloomberg::quantum::ITaskAccessor
using Ptr = std::shared_ptr< ITaskAccessor >
 

Public Member Functions

 ~Context ()
 
void terminate () final
 Terminates the object. More...
 
void setTask (ITask::Ptr task) final
 
ITask::Ptr getTask () const final
 
bool isBlocked () const final
 
bool isSleeping (bool updateTimer=false) final
 
bool valid () const final
 Determines if the future object associated with this context has a valid shared state with the corresponding promise. More...
 
bool validAt (int num) const final
 Determines if the future object associated with the 'num'-th continuation context is still valid. More...
 
int setException (std::exception_ptr ex) final
 Set an exception in the promise associated with the current IThreadContext or ICoroContext. More...
 
void waitAt (int num) const final
 Waits for the future in the 'num-th' continuation context to be ready. More...
 
std::future_status waitForAt (int num, std::chrono::milliseconds timeMs) const final
 Waits for the future in the 'num-th' continuation context to be ready for a maximum of 'timeMs' milliseconds. More...
 
void wait () const final
 Waits for the future associated with this context to be ready. More...
 
std::future_status waitFor (std::chrono::milliseconds timeMs) const final
 Waits for the future associated with this context to be ready for a maximum of 'timeMs' milliseconds. More...
 
void waitAll () const final
 Wait for all the futures in the continuation chain to be ready. More...
 
template<class V = RET>
NonBufferRetType< V > get ()
 Get the future value associated with this context. More...
 
template<class V = RET>
const NonBufferRetType< V > & getRef () const
 Get a reference the future value associated with this context. More...
 
template<class V , class = NonBufferType<RET,V>>
int set (V &&value)
 Set the promised value associated with this context. More...
 
template<class V , class = BufferType<RET,V>>
void push (V &&value)
 Push a single value into the promise buffer. More...
 
template<class V = RET>
BufferRetType< V > pull (bool &isBufferClosed)
 Pull a single value from the future buffer. More...
 
template<class OTHER_RET >
NonBufferRetType< OTHER_RET > getAt (int num)
 Get the future value from the 'num-th' continuation context. More...
 
template<class OTHER_RET >
const NonBufferRetType< OTHER_RET > & getRefAt (int num) const
 Get a reference to the future value from the 'num-th' continuation context. More...
 
void waitAt (int num, ICoroSync::Ptr sync) const final
 Waits for the future in the 'num-th' continuation context to be ready. More...
 
std::future_status waitForAt (int num, ICoroSync::Ptr sync, std::chrono::milliseconds timeMs) const final
 Waits for the future in the 'num-th' continuation context to be ready for a maximum of 'timeMs' milliseconds. More...
 
void wait (ICoroSync::Ptr sync) const final
 Waits for the future associated with this context to be ready. More...
 
std::future_status waitFor (ICoroSync::Ptr sync, std::chrono::milliseconds timeMs) const final
 Waits for the future associated with this context to be ready for a maximum of 'timeMs' milliseconds. More...
 
void waitAll (ICoroSync::Ptr sync) const final
 Wait for all the futures in the continuation chain to be ready. More...
 
template<class V = RET>
NonBufferRetType< V > get (ICoroSync::Ptr sync)
 Get the future value associated with this context. More...
 
template<class V = RET>
const NonBufferRetType< V > & getRef (ICoroSync::Ptr sync) const
 Get a reference the future value associated with this context. More...
 
template<class V , class = NonBufferType<RET,V>>
int set (ICoroSync::Ptr sync, V &&value)
 
template<class V , class = BufferType<RET,V>>
void push (ICoroSync::Ptr sync, V &&value)
 
template<class V = RET>
BufferRetType< V > pull (ICoroSync::Ptr sync, bool &isBufferClosed)
 Pull a single value from the future buffer. More...
 
template<class OTHER_RET >
NonBufferRetType< OTHER_RET > getAt (int num, ICoroSync::Ptr sync)
 Get the future value from the 'num-th' continuation context. More...
 
template<class OTHER_RET >
const NonBufferRetType< OTHER_RET > & getRefAt (int num, ICoroSync::Ptr sync) const
 Get a reference to the future value from the 'num-th' continuation context. More...
 
template<class OTHER_RET >
NonBufferRetType< OTHER_RET > getPrev (ICoroSync::Ptr sync)
 
template<class OTHER_RET >
const NonBufferRetType< OTHER_RET > & getPrevRef (ICoroSync::Ptr sync)
 
void setYieldHandle (Traits::Yield &yield) final
 Sets the underlying boost::coroutine object so that it can be yielded on. More...
 
Traits::YieldgetYieldHandle () final
 Retrieve the underlying boost::coroutine object. More...
 
void yield () final
 Explicitly yields this coroutine context. More...
 
std::atomic_int & signal () final
 Accessor to the underlying synchronization variable. More...
 
void sleep (const std::chrono::milliseconds &timeMs) final
 Sleeps the coroutine associated with this context for at least 'timeMs' milliseconds or 'timeUs' microseconds depending on the overload chosen. More...
 
void sleep (const std::chrono::microseconds &timeUs) final
 
template<class V = RET, class = BufferRetType<V>>
int closeBuffer ()
 Close a promise buffer. More...
 
int getNumCoroutineThreads () const
 Returns the number of underlying coroutine threads as specified in the dispatcher constructor. If -1 was passed than this number essentially indicates the number of cores. More...
 
int getNumIoThreads () const
 Returns the number of underlying IO threads as specified in the dispatcher constructor. More...
 
const std::pair< int, int > & getCoroQueueIdRangeForAny () const
 Gets the range [minQueueId, maxQueueId] of coroutine queueIds covered by IQueue::QueueId::Any by the Dispatcher. More...
 
template<class OTHER_RET , class FUNC , class ... ARGS>
Context< OTHER_RET >::Ptr post (FUNC &&func, ARGS &&... args)
 Post a coroutine to run asynchronously. More...
 
template<class OTHER_RET , class FUNC , class ... ARGS>
Context< OTHER_RET >::Ptr post (int queueId, bool isHighPriority, FUNC &&func, ARGS &&... args)
 Post a coroutine to run asynchronously. More...
 
template<class OTHER_RET , class FUNC , class ... ARGS>
Context< OTHER_RET >::Ptr postFirst (FUNC &&func, ARGS &&... args)
 Posts a coroutine to run asynchronously. More...
 
template<class OTHER_RET , class FUNC , class ... ARGS>
Context< OTHER_RET >::Ptr postFirst (int queueId, bool isHighPriority, FUNC &&func, ARGS &&... args)
 Posts a coroutine to run asynchronously. More...
 
template<class OTHER_RET , class FUNC , class ... ARGS>
Context< OTHER_RET >::Ptr then (FUNC &&func, ARGS &&... args)
 Posts a coroutine to run asynchronously. More...
 
template<class OTHER_RET , class FUNC , class ... ARGS>
Context< OTHER_RET >::Ptr onError (FUNC &&func, ARGS &&... args)
 Posts a coroutine to run asynchronously. This is the error handler for a continuation chain and acts as as a 'catch' clause. More...
 
template<class OTHER_RET , class FUNC , class ... ARGS>
Context< OTHER_RET >::Ptr finally (FUNC &&func, ARGS &&... args)
 Posts a coroutine to run asynchronously. This coroutine is always guaranteed to run. More...
 
Ptr end ()
 This is the last method in a continuation chain. More...
 
template<class OTHER_RET , class FUNC , class ... ARGS>
CoroFuturePtr< OTHER_RET > postAsyncIo (FUNC &&func, ARGS &&... args)
 Posts an IO method to run asynchronously on the IO thread pool. More...
 
template<class OTHER_RET , class FUNC , class ... ARGS>
CoroFuturePtr< OTHER_RET > postAsyncIo (int queueId, bool isHighPriority, FUNC &&func, ARGS &&... args)
 Posts an IO function to run asynchronously on the IO thread pool. More...
 
template<class OTHER_RET , class INPUT_IT , class = Traits::IsInputIterator<INPUT_IT>>
Context< std::vector< OTHER_RET > >::Ptr forEach (INPUT_IT first, INPUT_IT last, Functions::ForEachFunc< OTHER_RET, INPUT_IT > func)
 Applies the given unary function to all the elements in the range [first,last). This function runs in parallel. More...
 
template<class OTHER_RET , class INPUT_IT >
Context< std::vector< OTHER_RET > >::Ptr forEach (INPUT_IT first, size_t num, Functions::ForEachFunc< OTHER_RET, INPUT_IT > func)
 Applies the given unary function to all the elements in the range [first,first+num). This function runs in parallel. More...
 
template<class OTHER_RET , class INPUT_IT , class = Traits::IsInputIterator<INPUT_IT>>
Context< std::vector< std::vector< OTHER_RET > > >::Ptr forEachBatch (INPUT_IT first, INPUT_IT last, Functions::ForEachFunc< OTHER_RET, INPUT_IT > func)
 Applies the given unary function to all the elements in the range [first,last). This function runs serially with respect to other functions in the same batch. More...
 
template<class OTHER_RET , class INPUT_IT >
Context< std::vector< std::vector< OTHER_RET > > >::Ptr forEachBatch (INPUT_IT first, size_t num, Functions::ForEachFunc< OTHER_RET, INPUT_IT > func)
 Applies the given unary function to all the elements in the range [first,last). This function runs serially with respect to other functions in the same batch. More...
 
template<class KEY , class MAPPED_TYPE , class REDUCED_TYPE , class INPUT_IT , class = Traits::IsInputIterator<INPUT_IT>>
Context< std::map< KEY, REDUCED_TYPE > >::Ptr mapReduce (INPUT_IT first, INPUT_IT last, Functions::MapFunc< KEY, MAPPED_TYPE, INPUT_IT > mapper, Functions::ReduceFunc< KEY, MAPPED_TYPE, REDUCED_TYPE > reducer)
 Implementation of map-reduce functionality. More...
 
template<class KEY , class MAPPED_TYPE , class REDUCED_TYPE , class INPUT_IT >
Context< std::map< KEY, REDUCED_TYPE > >::Ptr mapReduce (INPUT_IT first, size_t num, Functions::MapFunc< KEY, MAPPED_TYPE, INPUT_IT > mapper, Functions::ReduceFunc< KEY, MAPPED_TYPE, REDUCED_TYPE > reducer)
 Same as mapReduce() but takes a length as second argument in case INPUT_IT is not a random access iterator. More...
 
template<class KEY , class MAPPED_TYPE , class REDUCED_TYPE , class INPUT_IT , class = Traits::IsInputIterator<INPUT_IT>>
Context< std::map< KEY, REDUCED_TYPE > >::Ptr mapReduceBatch (INPUT_IT first, INPUT_IT last, Functions::MapFunc< KEY, MAPPED_TYPE, INPUT_IT > mapper, Functions::ReduceFunc< KEY, MAPPED_TYPE, REDUCED_TYPE > reducer)
 This version of mapReduce() runs both the mapper and the reducer functions in batches for improved performance. This should be used in the case where the functions are more CPU intensive with little or no IO. More...
 
template<class KEY , class MAPPED_TYPE , class REDUCED_TYPE , class INPUT_IT >
Context< std::map< KEY, REDUCED_TYPE > >::Ptr mapReduceBatch (INPUT_IT first, size_t num, Functions::MapFunc< KEY, MAPPED_TYPE, INPUT_IT > mapper, Functions::ReduceFunc< KEY, MAPPED_TYPE, REDUCED_TYPE > reducer)
 Same as mapReduceBatch() but takes a length as second argument in case INPUT_IT is not a random access iterator. More...
 
template<class OTHER_RET , class FUNC , class ... ARGS>
ContextPtr< OTHER_RET > thenImpl (ITask::Type type, FUNC &&func, ARGS &&... args)
 
template<class OTHER_RET , class FUNC , class ... ARGS>
ContextPtr< OTHER_RET > then (FUNC &&func, ARGS &&... args)
 Posts a coroutine to run asynchronously. More...
 
template<class OTHER_RET , class FUNC , class ... ARGS>
ContextPtr< OTHER_RET > onError (FUNC &&func, ARGS &&... args)
 Posts a coroutine to run asynchronously. This is the error handler for a continuation chain and acts as as a 'catch' clause. More...
 
template<class OTHER_RET , class FUNC , class ... ARGS>
ContextPtr< OTHER_RET > finally (FUNC &&func, ARGS &&... args)
 Posts a coroutine to run asynchronously. This coroutine is always guaranteed to run. More...
 
template<class OTHER_RET , class INPUT_IT , class >
ContextPtr< std::vector< OTHER_RET > > forEach (INPUT_IT first, INPUT_IT last, Functions::ForEachFunc< OTHER_RET, INPUT_IT > func)
 Applies the given unary function to all the elements in the range [first,last). This function runs in parallel. More...
 
template<class OTHER_RET , class INPUT_IT >
ContextPtr< std::vector< OTHER_RET > > forEach (INPUT_IT first, size_t num, Functions::ForEachFunc< OTHER_RET, INPUT_IT > func)
 Applies the given unary function to all the elements in the range [first,first+num). This function runs in parallel. More...
 
template<class OTHER_RET , class INPUT_IT , class >
ContextPtr< std::vector< std::vector< OTHER_RET > > > forEachBatch (INPUT_IT first, INPUT_IT last, Functions::ForEachFunc< OTHER_RET, INPUT_IT > func)
 Applies the given unary function to all the elements in the range [first,last). This function runs serially with respect to other functions in the same batch. More...
 
template<class OTHER_RET , class INPUT_IT >
ContextPtr< std::vector< std::vector< OTHER_RET > > > forEachBatch (INPUT_IT first, size_t num, Functions::ForEachFunc< OTHER_RET, INPUT_IT > func)
 Applies the given unary function to all the elements in the range [first,last). This function runs serially with respect to other functions in the same batch. More...
 
template<class KEY , class MAPPED_TYPE , class REDUCED_TYPE , class INPUT_IT , class >
ContextPtr< std::map< KEY, REDUCED_TYPE > > mapReduce (INPUT_IT first, INPUT_IT last, Functions::MapFunc< KEY, MAPPED_TYPE, INPUT_IT > mapper, Functions::ReduceFunc< KEY, MAPPED_TYPE, REDUCED_TYPE > reducer)
 Implementation of map-reduce functionality. More...
 
template<class KEY , class MAPPED_TYPE , class REDUCED_TYPE , class INPUT_IT >
ContextPtr< std::map< KEY, REDUCED_TYPE > > mapReduce (INPUT_IT first, size_t num, Functions::MapFunc< KEY, MAPPED_TYPE, INPUT_IT > mapper, Functions::ReduceFunc< KEY, MAPPED_TYPE, REDUCED_TYPE > reducer)
 Same as mapReduce() but takes a length as second argument in case INPUT_IT is not a random access iterator. More...
 
template<class KEY , class MAPPED_TYPE , class REDUCED_TYPE , class INPUT_IT , class >
ContextPtr< std::map< KEY, REDUCED_TYPE > > mapReduceBatch (INPUT_IT first, INPUT_IT last, Functions::MapFunc< KEY, MAPPED_TYPE, INPUT_IT > mapper, Functions::ReduceFunc< KEY, MAPPED_TYPE, REDUCED_TYPE > reducer)
 This version of mapReduce() runs both the mapper and the reducer functions in batches for improved performance. This should be used in the case where the functions are more CPU intensive with little or no IO. More...
 
template<class KEY , class MAPPED_TYPE , class REDUCED_TYPE , class INPUT_IT >
ContextPtr< std::map< KEY, REDUCED_TYPE > > mapReduceBatch (INPUT_IT first, size_t num, Functions::MapFunc< KEY, MAPPED_TYPE, INPUT_IT > mapper, Functions::ReduceFunc< KEY, MAPPED_TYPE, REDUCED_TYPE > reducer)
 Same as mapReduceBatch() but takes a length as second argument in case INPUT_IT is not a random access iterator. More...
 
template<class OTHER_RET , class FUNC , class ... ARGS>
ContextPtr< OTHER_RET > post (FUNC &&func, ARGS &&... args)
 Post a coroutine to run asynchronously. More...
 
template<class OTHER_RET , class FUNC , class ... ARGS>
ContextPtr< OTHER_RET > post (int queueId, bool isHighPriority, FUNC &&func, ARGS &&... args)
 Post a coroutine to run asynchronously. More...
 
template<class OTHER_RET , class FUNC , class ... ARGS>
ContextPtr< OTHER_RET > postFirst (FUNC &&func, ARGS &&... args)
 Posts a coroutine to run asynchronously. More...
 
template<class OTHER_RET , class FUNC , class ... ARGS>
ContextPtr< OTHER_RET > postFirst (int queueId, bool isHighPriority, FUNC &&func, ARGS &&... args)
 Posts a coroutine to run asynchronously. More...
 
template<class OTHER_RET , class FUNC , class ... ARGS>
ContextPtr< OTHER_RET > postImpl (int queueId, bool isHighPriority, ITask::Type type, FUNC &&func, ARGS &&... args)
 
- Public Member Functions inherited from Bloomberg::quantum::IContextBase
virtual ~IContextBase ()=default
 Virtual destructor. More...
 
- Public Member Functions inherited from Bloomberg::quantum::ICoroContext< RET >
template<class OTHER_RET >
NonBufferRetType< OTHER_RET > getPrev ()
 Get the future value associated with the previous coroutine context in the continuation chain. More...
 
template<class OTHER_RET >
const NonBufferRetType< OTHER_RET > & getPrevRef ()
 Get a reference to future value associated with the previous coroutine context in the continuation chain. More...
 
- Public Member Functions inherited from Bloomberg::quantum::ICoroSync
virtual ~ICoroSync ()=default
 Default virtual destructor. More...
 
- Public Member Functions inherited from Bloomberg::quantum::ITerminate
virtual ~ITerminate ()=default
 Virtual destructor. This function is explicitly left empty. More...
 

Static Public Member Functions

static void * operator new (size_t size)
 
static void operator delete (void *p)
 
static void deleter (Context< RET > *p)
 

Friends

struct Util
 
class Task
 
class Dispatcher
 
template<class OTHER_RET >
class Context
 

Detailed Description

template<class RET>
class Bloomberg::quantum::Context< RET >

Concrete class representing a coroutine or a thread context.

Note
For internal use only. See interfaces ICoroContext and IThreadContext for usage details.

Member Typedef Documentation

◆ CoroCtx

template<class RET>
using Bloomberg::quantum::Context< RET >::CoroCtx = ICoroContext<RET>

◆ Ptr

template<class RET>
using Bloomberg::quantum::Context< RET >::Ptr = std::shared_ptr<Context<RET> >

◆ ThreadCtx

template<class RET>
using Bloomberg::quantum::Context< RET >::ThreadCtx = IThreadContext<RET>

Constructor & Destructor Documentation

◆ ~Context()

template<class RET >
Bloomberg::quantum::Context< RET >::~Context ( )

Member Function Documentation

◆ closeBuffer()

template<class RET >
template<class V , class >
int Bloomberg::quantum::Context< RET >::closeBuffer ( )

Close a promise buffer.

Template Parameters
BUFRepresents a class of type Buffer.
Note
Once closed no more Pushes can be made into the buffer. The corresponding future can still Pull values until the buffer is empty.
Returns
0 on success.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ deleter()

template<class RET >
void Bloomberg::quantum::Context< RET >::deleter ( Context< RET > *  p)
static

◆ end()

template<class RET >
Context< RET >::Ptr Bloomberg::quantum::Context< RET >::end ( )

This is the last method in a continuation chain.

This method effectively closes the continuation chain and posts the entire chain to be executed, respecting the 'queueId' and priority specified at the beginning of the chain (see postFirst()).

Returns
Pointer to this context.
Note
This method does not take any functions as parameter as it is strictly used for scheduling purposes.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ finally() [1/2]

template<class RET>
template<class OTHER_RET , class FUNC , class ... ARGS>
Context<OTHER_RET>::Ptr Bloomberg::quantum::Context< RET >::finally ( FUNC &&  func,
ARGS &&...  args 
)

Posts a coroutine to run asynchronously. This coroutine is always guaranteed to run.

This function is optional for the continuation chain and may be called at most once. If called, it must immediately precede the end() method. This method will run regardless if any preceding coroutines have an error or not. It can be used for cleanup purposes, closing handles, terminating services, etc.

Template Parameters
OTHER_RETType of future returned by this coroutine.
FUNCCallable object type which will be wrapped in a coroutine. Can be a standalone function, a method, an std::function, a functor generated via std::bind or a lambda. The signature of the callable object must strictly be 'int f(CoroContext<RET>::Ptr, ...)'.
ARGSArgument types passed to FUNC.
Parameters
[in]funcCallable object.
[in]argsVariable list of arguments passed to the callable object.
Returns
A pointer to a coroutine context object.
Note
This function is non-blocking and returns immediately. After this coroutine, the end() method must be called.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ finally() [2/2]

template<class RET>
template<class OTHER_RET , class FUNC , class ... ARGS>
ContextPtr<OTHER_RET> Bloomberg::quantum::Context< RET >::finally ( FUNC &&  func,
ARGS &&...  args 
)

Posts a coroutine to run asynchronously. This coroutine is always guaranteed to run.

This function is optional for the continuation chain and may be called at most once. If called, it must immediately precede the end() method. This method will run regardless if any preceding coroutines have an error or not. It can be used for cleanup purposes, closing handles, terminating services, etc.

Template Parameters
OTHER_RETType of future returned by this coroutine.
FUNCCallable object type which will be wrapped in a coroutine. Can be a standalone function, a method, an std::function, a functor generated via std::bind or a lambda. The signature of the callable object must strictly be 'int f(CoroContext<RET>::Ptr, ...)'.
ARGSArgument types passed to FUNC.
Parameters
[in]funcCallable object.
[in]argsVariable list of arguments passed to the callable object.
Returns
A pointer to a coroutine context object.
Note
This function is non-blocking and returns immediately. After this coroutine, the end() method must be called.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ forEach() [1/4]

template<class RET>
template<class OTHER_RET , class INPUT_IT , class = Traits::IsInputIterator<INPUT_IT>>
Context<std::vector<OTHER_RET> >::Ptr Bloomberg::quantum::Context< RET >::forEach ( INPUT_IT  first,
INPUT_IT  last,
Functions::ForEachFunc< OTHER_RET, INPUT_IT >  func 
)

Applies the given unary function to all the elements in the range [first,last). This function runs in parallel.

Template Parameters
OTHER_RETThe return value of the unary function.
UNARY_FUNCA unary function of type 'RET(*INPUT_IT)'.
InputItThe type of iterator.
Parameters
[in]firstThe first element in the range.
[in]lastThe last element in the range (exclusive).
[in]funcThe unary function.
Returns
A vector of future values corresponding to the output of 'func' on every element in the range.
Note
Use this function if InputIt meets the requirement of a RandomAccessIterator
Each func invocation will run inside its own coroutine instance.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ forEach() [2/4]

template<class RET>
template<class OTHER_RET , class INPUT_IT >
Context<std::vector<OTHER_RET> >::Ptr Bloomberg::quantum::Context< RET >::forEach ( INPUT_IT  first,
size_t  num,
Functions::ForEachFunc< OTHER_RET, INPUT_IT >  func 
)

Applies the given unary function to all the elements in the range [first,first+num). This function runs in parallel.

Template Parameters
OTHER_RETThe return value of the unary function.
UNARY_FUNCA unary function of type 'RET(*INPUT_IT)'.
InputItThe type of iterator. @oaram[in] first The first element in the range. @oaram[in] num The number of elements to iterate over. @oaram[in] func The unary function.
Returns
A vector of future values corresponding to the output of 'func' on every element in the range.
Note
Use this function if InputIt does not meet the requirement of a RandomAccessIterator.
Each func invocation will run inside its own coroutine instance.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ forEach() [3/4]

template<class RET>
template<class OTHER_RET , class INPUT_IT , class >
ContextPtr<std::vector<OTHER_RET> > Bloomberg::quantum::Context< RET >::forEach ( INPUT_IT  first,
INPUT_IT  last,
Functions::ForEachFunc< OTHER_RET, INPUT_IT >  func 
)

Applies the given unary function to all the elements in the range [first,last). This function runs in parallel.

Template Parameters
OTHER_RETThe return value of the unary function.
UNARY_FUNCA unary function of type 'RET(*INPUT_IT)'.
InputItThe type of iterator.
Parameters
[in]firstThe first element in the range.
[in]lastThe last element in the range (exclusive).
[in]funcThe unary function.
Returns
A vector of future values corresponding to the output of 'func' on every element in the range.
Note
Use this function if InputIt meets the requirement of a RandomAccessIterator
Each func invocation will run inside its own coroutine instance.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ forEach() [4/4]

template<class RET>
template<class OTHER_RET , class INPUT_IT >
ContextPtr<std::vector<OTHER_RET> > Bloomberg::quantum::Context< RET >::forEach ( INPUT_IT  first,
size_t  num,
Functions::ForEachFunc< OTHER_RET, INPUT_IT >  func 
)

Applies the given unary function to all the elements in the range [first,first+num). This function runs in parallel.

Template Parameters
OTHER_RETThe return value of the unary function.
UNARY_FUNCA unary function of type 'RET(*INPUT_IT)'.
InputItThe type of iterator. @oaram[in] first The first element in the range. @oaram[in] num The number of elements to iterate over. @oaram[in] func The unary function.
Returns
A vector of future values corresponding to the output of 'func' on every element in the range.
Note
Use this function if InputIt does not meet the requirement of a RandomAccessIterator.
Each func invocation will run inside its own coroutine instance.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ forEachBatch() [1/4]

template<class RET>
template<class OTHER_RET , class INPUT_IT , class = Traits::IsInputIterator<INPUT_IT>>
Context<std::vector<std::vector<OTHER_RET> > >::Ptr Bloomberg::quantum::Context< RET >::forEachBatch ( INPUT_IT  first,
INPUT_IT  last,
Functions::ForEachFunc< OTHER_RET, INPUT_IT >  func 
)

Applies the given unary function to all the elements in the range [first,last). This function runs serially with respect to other functions in the same batch.

Template Parameters
OTHER_RETThe return value of the unary function.
UNARY_FUNCA unary function of type 'RET(*INPUT_IT)'.
InputItThe type of iterator. @oaram[in] first The first element in the range. @oaram[in] last The last element in the range (exclusive). @oaram[in] func The unary function.
Returns
A vector of value vectors (i.e. one per batch).
Note
Use this function if InputIt meets the requirement of a RandomAccessIterator.
The input range is split equally among coroutines and executed in batches. This function achieves higher throughput rates than the non-batched mode, if func() is CPU-bound.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ forEachBatch() [2/4]

template<class RET>
template<class OTHER_RET , class INPUT_IT >
Context<std::vector<std::vector<OTHER_RET> > >::Ptr Bloomberg::quantum::Context< RET >::forEachBatch ( INPUT_IT  first,
size_t  num,
Functions::ForEachFunc< OTHER_RET, INPUT_IT >  func 
)

Applies the given unary function to all the elements in the range [first,last). This function runs serially with respect to other functions in the same batch.

Template Parameters
OTHER_RETThe return value of the unary function.
UNARY_FUNCA unary function of type 'RET(*INPUT_IT)'.
InputItThe type of iterator. @oaram[in] first The first element in the range. @oaram[in] last The last element in the range (exclusive). @oaram[in] func The unary function.
Returns
A vector of value vectors (i.e. one per batch).
Note
Use this function if InputIt does not meet the requirement of a RandomAccessIterator.
The input range is split equally among coroutines and executed in batches. This function achieves higher throughput rates than the non-batched mode, if func() is CPU-bound.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ forEachBatch() [3/4]

template<class RET>
template<class OTHER_RET , class INPUT_IT , class >
ContextPtr<std::vector<std::vector<OTHER_RET> > > Bloomberg::quantum::Context< RET >::forEachBatch ( INPUT_IT  first,
INPUT_IT  last,
Functions::ForEachFunc< OTHER_RET, INPUT_IT >  func 
)

Applies the given unary function to all the elements in the range [first,last). This function runs serially with respect to other functions in the same batch.

Template Parameters
OTHER_RETThe return value of the unary function.
UNARY_FUNCA unary function of type 'RET(*INPUT_IT)'.
InputItThe type of iterator. @oaram[in] first The first element in the range. @oaram[in] last The last element in the range (exclusive). @oaram[in] func The unary function.
Returns
A vector of value vectors (i.e. one per batch).
Note
Use this function if InputIt meets the requirement of a RandomAccessIterator.
The input range is split equally among coroutines and executed in batches. This function achieves higher throughput rates than the non-batched mode, if func() is CPU-bound.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ forEachBatch() [4/4]

template<class RET>
template<class OTHER_RET , class INPUT_IT >
ContextPtr<std::vector<std::vector<OTHER_RET> > > Bloomberg::quantum::Context< RET >::forEachBatch ( INPUT_IT  first,
size_t  num,
Functions::ForEachFunc< OTHER_RET, INPUT_IT >  func 
)

Applies the given unary function to all the elements in the range [first,last). This function runs serially with respect to other functions in the same batch.

Template Parameters
OTHER_RETThe return value of the unary function.
UNARY_FUNCA unary function of type 'RET(*INPUT_IT)'.
InputItThe type of iterator. @oaram[in] first The first element in the range. @oaram[in] last The last element in the range (exclusive). @oaram[in] func The unary function.
Returns
A vector of value vectors (i.e. one per batch).
Note
Use this function if InputIt does not meet the requirement of a RandomAccessIterator.
The input range is split equally among coroutines and executed in batches. This function achieves higher throughput rates than the non-batched mode, if func() is CPU-bound.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ get() [1/2]

template<class RET >
template<class V >
NonBufferRetType< V > Bloomberg::quantum::Context< RET >::get ( )

Get the future value associated with this context.

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::IThreadContext< RET >.

◆ get() [2/2]

template<class RET >
template<class V >
NonBufferRetType< V > Bloomberg::quantum::Context< RET >::get ( ICoroSync::Ptr  sync)

Get the future value associated with this context.

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::ICoroContext< RET >.

◆ getAt() [1/2]

template<class RET >
template<class OTHER_RET >
NonBufferRetType< OTHER_RET > Bloomberg::quantum::Context< RET >::getAt ( int  num)

Get the future value from the 'num-th' continuation context.

Allowed range for num is [-1, total_continuations). -1 is equivalent of calling get() or getAt(total_continuations-1) on the last context in the chain (i.e. the context which is returned via end()). Position 0 represents the first future in the chain.

Template Parameters
OTHER_RETThe type of the future value associated with the 'num-th' context.
Parameters
[in]numThe number indicating which future to wait on.
Returns
The future value of the 'num-th' thread context.
Note
Blocks until the future is ready or until an exception is thrown. Once this function returns, the future is invalidated (i.e. cannot be read again).

Implements Bloomberg::quantum::IThreadContext< RET >.

◆ getAt() [2/2]

template<class RET >
template<class OTHER_RET >
NonBufferRetType< OTHER_RET > Bloomberg::quantum::Context< RET >::getAt ( int  num,
ICoroSync::Ptr  sync 
)

Get the future value from the 'num-th' continuation context.

Allowed range for num is [-1, total_continuations). -1 is equivalent of calling get() or getAt(total_continuations-1) on the last context in the chain (i.e. the context which is returned via end()). Position 0 represents the first future in the chain.

Template Parameters
OTHER_RETThe type of the future value associated with the 'num-th' context.
Parameters
[in]numThe number indicating which future to wait on.
[in]syncPointer to the coroutine synchronization object.
Returns
The future value of the 'num-th' coroutine context.
Note
Blocks until the future is ready or until an exception is thrown. Once this function returns, the future is invalidated (i.e. cannot be read again).

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ getCoroQueueIdRangeForAny()

template<class RET >
const std::pair< int, int > & Bloomberg::quantum::Context< RET >::getCoroQueueIdRangeForAny ( ) const

Gets the range [minQueueId, maxQueueId] of coroutine queueIds covered by IQueue::QueueId::Any by the Dispatcher.

Returns
queueIdRange The range of queueIds that IQueue::QueueId::Any covers

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ getNumCoroutineThreads()

template<class RET >
int Bloomberg::quantum::Context< RET >::getNumCoroutineThreads ( ) const

Returns the number of underlying coroutine threads as specified in the dispatcher constructor. If -1 was passed than this number essentially indicates the number of cores.

Returns
The number of threads.
Note
Each thread services its own queueId, therefore this number can be used when assigning coroutines to a specific queue.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ getNumIoThreads()

template<class RET >
int Bloomberg::quantum::Context< RET >::getNumIoThreads ( ) const

Returns the number of underlying IO threads as specified in the dispatcher constructor.

Returns
The number of threads.
Note
Each thread services its own queueId, therefore this number can be used when assigning IO tasks to a specific queue.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ getPrev()

template<class RET >
template<class OTHER_RET >
NonBufferRetType< OTHER_RET > Bloomberg::quantum::Context< RET >::getPrev ( ICoroSync::Ptr  sync)

◆ getPrevRef()

template<class RET >
template<class OTHER_RET >
const NonBufferRetType< OTHER_RET > & Bloomberg::quantum::Context< RET >::getPrevRef ( ICoroSync::Ptr  sync)

◆ getRef() [1/2]

template<class RET >
template<class V >
const NonBufferRetType< V > & Bloomberg::quantum::Context< RET >::getRef ( ) const

Get a reference the future value associated with this context.

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::IThreadContext< RET >.

◆ getRef() [2/2]

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

Get a reference the future value associated with this context.

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::ICoroContext< RET >.

◆ getRefAt() [1/2]

template<class RET >
template<class OTHER_RET >
const NonBufferRetType< OTHER_RET > & Bloomberg::quantum::Context< RET >::getRefAt ( int  num) const

Get a reference to the future value from the 'num-th' continuation context.

Allowed range for num is [-1, total_continuations). -1 is equivalent of calling get() or getAt(total_continuations-1) on the last context in the chain (i.e. the context which is returned via end()). Position 0 represents the first future in the chain.

Template Parameters
OTHER_RETThe type of the future value associated with the 'num-th' context.
Parameters
[in]numThe number indicating which future to wait on.
Returns
A reference to the future value of the 'num-th' thread context.
Note
Blocks until the future is ready or until an exception is thrown. Contrary to getAt() this function will not invalidate the future and as such it can be read again.

Implements Bloomberg::quantum::IThreadContext< RET >.

◆ getRefAt() [2/2]

template<class RET >
template<class OTHER_RET >
const NonBufferRetType< OTHER_RET > & Bloomberg::quantum::Context< RET >::getRefAt ( int  num,
ICoroSync::Ptr  sync 
) const

Get a reference to the future value from the 'num-th' continuation context.

Allowed range for num is [-1, total_continuations). -1 is equivalent of calling get() or getAt(total_continuations-1) on the last context in the chain (i.e. the context which is returned via end()). Position 0 represents the first future in the chain.

Template Parameters
OTHER_RETThe type of the future value associated with the 'num-th' context.
Parameters
[in]numThe number indicating which future to wait on.
[in]syncPointer to the coroutine synchronization object.
Returns
A reference to the future value of the 'num-th' coroutine context.
Note
Blocks until the future is ready or until an exception is thrown. Contrary to getAt() this function will not invalidate the future and as such it can be read again.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ getTask()

template<class RET >
ITask::Ptr Bloomberg::quantum::Context< RET >::getTask ( ) const
finalvirtual

◆ getYieldHandle()

template<class RET >
Traits::Yield & Bloomberg::quantum::Context< RET >::getYieldHandle ( )
finalvirtual

Retrieve the underlying boost::coroutine object.

Returns
The associated boost::coroutine object held by this class.
Exceptions
Ifthe underlying boost::coroutine is not set.

Implements Bloomberg::quantum::ICoroSync.

◆ isBlocked()

template<class RET >
bool Bloomberg::quantum::Context< RET >::isBlocked ( ) const
finalvirtual

◆ isSleeping()

template<class RET >
bool Bloomberg::quantum::Context< RET >::isSleeping ( bool  updateTimer = false)
finalvirtual

◆ mapReduce() [1/4]

template<class RET>
template<class KEY , class MAPPED_TYPE , class REDUCED_TYPE , class INPUT_IT , class = Traits::IsInputIterator<INPUT_IT>>
Context<std::map<KEY, REDUCED_TYPE> >::Ptr Bloomberg::quantum::Context< RET >::mapReduce ( INPUT_IT  first,
INPUT_IT  last,
Functions::MapFunc< KEY, MAPPED_TYPE, INPUT_IT >  mapper,
Functions::ReduceFunc< KEY, MAPPED_TYPE, REDUCED_TYPE >  reducer 
)

Implementation of map-reduce functionality.

Template Parameters
KEYThe KEY type used for mapping and reducing.
MAPPED_TYPEThe output type after a map operation.
REDUCED_TYPEThe output type after a reduce operation.
MAPPER_FUNCThe mapper function having the signature 'std::vector<std::pair<KEY,MAPPED_TYPE>>(*INPUT_IT)'
REDUCER_FUNCThe reducer function having the signature 'std::pair<KEY,REDUCED_TYPE>(std::pair<KEY, std::vector<MAPPED_TYPE>>&&)'
INPUT_ITThe iterator type. @oaram[in] first The start iterator to a list of items to be processed in the range [first,last). @oaram[in] last The end iterator to a list of items (not inclusive). @oaram[in] mapper The mapper function. @oaram[in] reducer The reducer function.
Returns
A future to a reduced map of values.
Note
Use this function if InputIt meets the requirement of a RandomAccessIterator.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ mapReduce() [2/4]

template<class RET>
template<class KEY , class MAPPED_TYPE , class REDUCED_TYPE , class INPUT_IT >
Context<std::map<KEY, REDUCED_TYPE> >::Ptr Bloomberg::quantum::Context< RET >::mapReduce ( INPUT_IT  first,
size_t  num,
Functions::MapFunc< KEY, MAPPED_TYPE, INPUT_IT >  mapper,
Functions::ReduceFunc< KEY, MAPPED_TYPE, REDUCED_TYPE >  reducer 
)

Same as mapReduce() but takes a length as second argument in case INPUT_IT is not a random access iterator.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ mapReduce() [3/4]

template<class RET>
template<class KEY , class MAPPED_TYPE , class REDUCED_TYPE , class INPUT_IT , class >
ContextPtr<std::map<KEY, REDUCED_TYPE> > Bloomberg::quantum::Context< RET >::mapReduce ( INPUT_IT  first,
INPUT_IT  last,
Functions::MapFunc< KEY, MAPPED_TYPE, INPUT_IT >  mapper,
Functions::ReduceFunc< KEY, MAPPED_TYPE, REDUCED_TYPE >  reducer 
)

Implementation of map-reduce functionality.

Template Parameters
KEYThe KEY type used for mapping and reducing.
MAPPED_TYPEThe output type after a map operation.
REDUCED_TYPEThe output type after a reduce operation.
MAPPER_FUNCThe mapper function having the signature 'std::vector<std::pair<KEY,MAPPED_TYPE>>(*INPUT_IT)'
REDUCER_FUNCThe reducer function having the signature 'std::pair<KEY,REDUCED_TYPE>(std::pair<KEY, std::vector<MAPPED_TYPE>>&&)'
INPUT_ITThe iterator type. @oaram[in] first The start iterator to a list of items to be processed in the range [first,last). @oaram[in] last The end iterator to a list of items (not inclusive). @oaram[in] mapper The mapper function. @oaram[in] reducer The reducer function.
Returns
A future to a reduced map of values.
Note
Use this function if InputIt meets the requirement of a RandomAccessIterator.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ mapReduce() [4/4]

template<class RET>
template<class KEY , class MAPPED_TYPE , class REDUCED_TYPE , class INPUT_IT >
ContextPtr<std::map<KEY, REDUCED_TYPE> > Bloomberg::quantum::Context< RET >::mapReduce ( INPUT_IT  first,
size_t  num,
Functions::MapFunc< KEY, MAPPED_TYPE, INPUT_IT >  mapper,
Functions::ReduceFunc< KEY, MAPPED_TYPE, REDUCED_TYPE >  reducer 
)

Same as mapReduce() but takes a length as second argument in case INPUT_IT is not a random access iterator.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ mapReduceBatch() [1/4]

template<class RET>
template<class KEY , class MAPPED_TYPE , class REDUCED_TYPE , class INPUT_IT , class = Traits::IsInputIterator<INPUT_IT>>
Context<std::map<KEY, REDUCED_TYPE> >::Ptr Bloomberg::quantum::Context< RET >::mapReduceBatch ( INPUT_IT  first,
INPUT_IT  last,
Functions::MapFunc< KEY, MAPPED_TYPE, INPUT_IT >  mapper,
Functions::ReduceFunc< KEY, MAPPED_TYPE, REDUCED_TYPE >  reducer 
)

This version of mapReduce() runs both the mapper and the reducer functions in batches for improved performance. This should be used in the case where the functions are more CPU intensive with little or no IO.

Note
Use this function if InputIt meets the requirement of a RandomAccessIterator.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ mapReduceBatch() [2/4]

template<class RET>
template<class KEY , class MAPPED_TYPE , class REDUCED_TYPE , class INPUT_IT >
Context<std::map<KEY, REDUCED_TYPE> >::Ptr Bloomberg::quantum::Context< RET >::mapReduceBatch ( INPUT_IT  first,
size_t  num,
Functions::MapFunc< KEY, MAPPED_TYPE, INPUT_IT >  mapper,
Functions::ReduceFunc< KEY, MAPPED_TYPE, REDUCED_TYPE >  reducer 
)

Same as mapReduceBatch() but takes a length as second argument in case INPUT_IT is not a random access iterator.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ mapReduceBatch() [3/4]

template<class RET>
template<class KEY , class MAPPED_TYPE , class REDUCED_TYPE , class INPUT_IT , class >
ContextPtr<std::map<KEY, REDUCED_TYPE> > Bloomberg::quantum::Context< RET >::mapReduceBatch ( INPUT_IT  first,
INPUT_IT  last,
Functions::MapFunc< KEY, MAPPED_TYPE, INPUT_IT >  mapper,
Functions::ReduceFunc< KEY, MAPPED_TYPE, REDUCED_TYPE >  reducer 
)

This version of mapReduce() runs both the mapper and the reducer functions in batches for improved performance. This should be used in the case where the functions are more CPU intensive with little or no IO.

Note
Use this function if InputIt meets the requirement of a RandomAccessIterator.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ mapReduceBatch() [4/4]

template<class RET>
template<class KEY , class MAPPED_TYPE , class REDUCED_TYPE , class INPUT_IT >
ContextPtr<std::map<KEY, REDUCED_TYPE> > Bloomberg::quantum::Context< RET >::mapReduceBatch ( INPUT_IT  first,
size_t  num,
Functions::MapFunc< KEY, MAPPED_TYPE, INPUT_IT >  mapper,
Functions::ReduceFunc< KEY, MAPPED_TYPE, REDUCED_TYPE >  reducer 
)

Same as mapReduceBatch() but takes a length as second argument in case INPUT_IT is not a random access iterator.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ onError() [1/2]

template<class RET>
template<class OTHER_RET , class FUNC , class ... ARGS>
Context<OTHER_RET>::Ptr Bloomberg::quantum::Context< RET >::onError ( FUNC &&  func,
ARGS &&...  args 
)

Posts a coroutine to run asynchronously. This is the error handler for a continuation chain and acts as as a 'catch' clause.

This function is optional for the continuation chain and may be called at most once. If called, it must follow postFirst() or another then() method. This method will conditionally run if-and-only-if any previous coroutines in the continuation chain return an error or throw. When a coroutine which is part of a continuation chain has an error, all subsequent then() methods are skipped and if onError() is provided it will be called. If there are no errors, this method is skipped.

Template Parameters
OTHER_RETType of future returned by this coroutine.
FUNCCallable object type which will be wrapped in a coroutine. Can be a standalone function, a method, an std::function, a functor generated via std::bind or a lambda. The signature of the callable object must strictly be 'int f(CoroContext<RET>::Ptr, ...)'.
ARGSArgument types passed to FUNC.
Parameters
[in]funcCallable object.
[in]argsVariable list of arguments passed to the callable object.
Returns
A pointer to a coroutine context object.
Note
The function is non-blocking. The returned context can be used to chain further coroutines. Possible method calls following this are finally() and end().

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ onError() [2/2]

template<class RET>
template<class OTHER_RET , class FUNC , class ... ARGS>
ContextPtr<OTHER_RET> Bloomberg::quantum::Context< RET >::onError ( FUNC &&  func,
ARGS &&...  args 
)

Posts a coroutine to run asynchronously. This is the error handler for a continuation chain and acts as as a 'catch' clause.

This function is optional for the continuation chain and may be called at most once. If called, it must follow postFirst() or another then() method. This method will conditionally run if-and-only-if any previous coroutines in the continuation chain return an error or throw. When a coroutine which is part of a continuation chain has an error, all subsequent then() methods are skipped and if onError() is provided it will be called. If there are no errors, this method is skipped.

Template Parameters
OTHER_RETType of future returned by this coroutine.
FUNCCallable object type which will be wrapped in a coroutine. Can be a standalone function, a method, an std::function, a functor generated via std::bind or a lambda. The signature of the callable object must strictly be 'int f(CoroContext<RET>::Ptr, ...)'.
ARGSArgument types passed to FUNC.
Parameters
[in]funcCallable object.
[in]argsVariable list of arguments passed to the callable object.
Returns
A pointer to a coroutine context object.
Note
The function is non-blocking. The returned context can be used to chain further coroutines. Possible method calls following this are finally() and end().

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ operator delete()

template<class RET >
void Bloomberg::quantum::Context< RET >::operator delete ( void *  p)
static

◆ operator new()

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

◆ post() [1/4]

template<class RET>
template<class OTHER_RET , class FUNC , class ... ARGS>
Context<OTHER_RET>::Ptr Bloomberg::quantum::Context< RET >::post ( FUNC &&  func,
ARGS &&...  args 
)

Post a coroutine to run asynchronously.

Attention
Continuation methods are typically chained in the following manner and must follow the relative placement below. postFirst() and end() are the only mandatory methods. onError() and finally() can be called at most once, whereas then() may be called zero or more times.
ICoroContext<RET>::Ptr ctx = ICoroContext::postFirst()->then()->...->then()->onError()->finally()->end();
Note
post() methods are standalone and do not allow continuations.

This method will post the coroutine on any thread available. Typically it will pick one which has the smallest number of concurrent coroutines executing at the time of the post.

Template Parameters
OTHER_RETType of future returned by this coroutine.
FUNCCallable object type which will be wrapped in a coroutine. Can be a standalone function, a method, an std::function, a functor generated via std::bind or a lambda. The signature of the callable object must strictly be 'int f(CoroContext<RET>::Ptr, ...)'.
ARGSArgument types passed to FUNC.
Parameters
[in]funcCallable object.
[in]argsVariable list of arguments passed to the callable object.
Returns
A pointer to a coroutine context object.
Note
This function is non-blocking and returns immediately. The returned context cannot be used to chain further coroutines.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ post() [2/4]

template<class RET>
template<class OTHER_RET , class FUNC , class ... ARGS>
Context<OTHER_RET>::Ptr Bloomberg::quantum::Context< RET >::post ( int  queueId,
bool  isHighPriority,
FUNC &&  func,
ARGS &&...  args 
)

Post a coroutine to run asynchronously.

This method will post the coroutine on the specified queue (thread) with high or low priority.

Template Parameters
OTHER_RETType of future returned by this coroutine.
FUNCCallable object type which will be wrapped in a coroutine. Can be a standalone function, a method, an std::function, a functor generated via std::bind or a lambda. The signature of the callable object must strictly be 'int f(CoroContext<RET>::Ptr, ...)'.
ARGSArgument types passed to FUNC.
Parameters
[in]queueIdId of the queue where this coroutine should run. Note that the user can specify IQueue::QueueId::Any as a value, which is equivalent to running the simpler version of post() above. Valid range is [0, numCoroutineThreads), IQueue::QueueId::Any or IQueue::QueueId::Same. When using IQueue::QueueId::Same as input, the current queueId of this execution context will be preserved for the posted coroutine thus enabling to write lock-free code.
[in]isHighPriorityIf set to true, the coroutine will be scheduled to run immediately after the currently executing coroutine on 'queueId' has completed or has yielded.
[in]funcCallable object.
[in]argsVariable list of arguments passed to the callable object.
Returns
A pointer to a coroutine context object.
Note
This function is non-blocking and returns immediately. The returned context cannot be used to chain further coroutines.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ post() [3/4]

template<class RET>
template<class OTHER_RET , class FUNC , class ... ARGS>
ContextPtr<OTHER_RET> Bloomberg::quantum::Context< RET >::post ( FUNC &&  func,
ARGS &&...  args 
)

Post a coroutine to run asynchronously.

Attention
Continuation methods are typically chained in the following manner and must follow the relative placement below. postFirst() and end() are the only mandatory methods. onError() and finally() can be called at most once, whereas then() may be called zero or more times.
ICoroContext<RET>::Ptr ctx = ICoroContext::postFirst()->then()->...->then()->onError()->finally()->end();
Note
post() methods are standalone and do not allow continuations.

This method will post the coroutine on any thread available. Typically it will pick one which has the smallest number of concurrent coroutines executing at the time of the post.

Template Parameters
OTHER_RETType of future returned by this coroutine.
FUNCCallable object type which will be wrapped in a coroutine. Can be a standalone function, a method, an std::function, a functor generated via std::bind or a lambda. The signature of the callable object must strictly be 'int f(CoroContext<RET>::Ptr, ...)'.
ARGSArgument types passed to FUNC.
Parameters
[in]funcCallable object.
[in]argsVariable list of arguments passed to the callable object.
Returns
A pointer to a coroutine context object.
Note
This function is non-blocking and returns immediately. The returned context cannot be used to chain further coroutines.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ post() [4/4]

template<class RET>
template<class OTHER_RET , class FUNC , class ... ARGS>
ContextPtr<OTHER_RET> Bloomberg::quantum::Context< RET >::post ( int  queueId,
bool  isHighPriority,
FUNC &&  func,
ARGS &&...  args 
)

Post a coroutine to run asynchronously.

This method will post the coroutine on the specified queue (thread) with high or low priority.

Template Parameters
OTHER_RETType of future returned by this coroutine.
FUNCCallable object type which will be wrapped in a coroutine. Can be a standalone function, a method, an std::function, a functor generated via std::bind or a lambda. The signature of the callable object must strictly be 'int f(CoroContext<RET>::Ptr, ...)'.
ARGSArgument types passed to FUNC.
Parameters
[in]queueIdId of the queue where this coroutine should run. Note that the user can specify IQueue::QueueId::Any as a value, which is equivalent to running the simpler version of post() above. Valid range is [0, numCoroutineThreads), IQueue::QueueId::Any or IQueue::QueueId::Same. When using IQueue::QueueId::Same as input, the current queueId of this execution context will be preserved for the posted coroutine thus enabling to write lock-free code.
[in]isHighPriorityIf set to true, the coroutine will be scheduled to run immediately after the currently executing coroutine on 'queueId' has completed or has yielded.
[in]funcCallable object.
[in]argsVariable list of arguments passed to the callable object.
Returns
A pointer to a coroutine context object.
Note
This function is non-blocking and returns immediately. The returned context cannot be used to chain further coroutines.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ postAsyncIo() [1/2]

template<class RET >
template<class OTHER_RET , class FUNC , class ... ARGS>
CoroFuturePtr< OTHER_RET > Bloomberg::quantum::Context< RET >::postAsyncIo ( FUNC &&  func,
ARGS &&...  args 
)

Posts an IO method to run asynchronously on the IO thread pool.

Template Parameters
OTHER_RETType of future returned by this function.
FUNCCallable object type. Can be a standalone function, a method, an std::function, a functor generated via std::bind or a lambda. The signature of the callable object must strictly be 'int f(ThreadPromise<RET>::Ptr, ...)'.
ARGSArgument types passed to FUNC.
Parameters
[in]funcCallable object.
[in]argsVariable list of arguments passed to the callable object.
Returns
A pointer to a coroutine future object which may be used to retrieve the result of the IO operation.
Note
This method does not block. The passed function will not be wrapped in a coroutine.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ postAsyncIo() [2/2]

template<class RET >
template<class OTHER_RET , class FUNC , class ... ARGS>
CoroFuturePtr< OTHER_RET > Bloomberg::quantum::Context< RET >::postAsyncIo ( int  queueId,
bool  isHighPriority,
FUNC &&  func,
ARGS &&...  args 
)

Posts an IO function to run asynchronously on the IO thread pool.

This method will post the function on the specified queue (thread) with high or low priority.

Template Parameters
OTHER_RETType of future returned by this function.
FUNCCallable object type. Can be a standalone function, a method, an std::function, a functor generated via std::bind or a lambda. The signature of the callable object must strictly be 'int f(ThreadPromise<RET>::Ptr, ...)'.
ARGSArgument types passed to FUNC.
Parameters
[in]queueIdId of the queue where this function should run. Note that the user can specify IQueue::QueueId::Any as a value, which is equivalent to running the simpler version of postAsyncIo() above. Valid range is [0, numIoThreads) or IQueue::QueueId::Any. IQueue::QueueId::Same is disallowed.
[in]isHighPriorityIf set to true, the function will be scheduled to run immediately after the currently executing function on 'queueId' has completed.
[in]funcCallable object.
[in]argsVariable list of arguments passed to the callable object.
Returns
A pointer to a coroutine future object which may be used to retrieve the result of the IO operation.
Note
This method does not block. The passed function will not be wrapped in a coroutine.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ postFirst() [1/4]

template<class RET>
template<class OTHER_RET , class FUNC , class ... ARGS>
Context<OTHER_RET>::Ptr Bloomberg::quantum::Context< RET >::postFirst ( FUNC &&  func,
ARGS &&...  args 
)

Posts a coroutine to run asynchronously.

This function is the head of a coroutine continuation chain and must be called only once in the chain.

Template Parameters
OTHER_RETType of future returned by this coroutine.
FUNCCallable object type which will be wrapped in a coroutine. Can be a standalone function, a method, an std::function, a functor generated via std::bind or a lambda. The signature of the callable object must strictly be 'int f(CoroContext<RET>::Ptr, ...)'.
ARGSArgument types passed to FUNC.
Parameters
[in]funcCallable object.
[in]argsVariable list of arguments passed to the callable object.
Returns
A pointer to a coroutine context object.
Note
This function is non-blocking and returns immediately. The returned context can be used to chain further coroutines. Possible method calls following this are then(), onError(), finally() and end().

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ postFirst() [2/4]

template<class RET>
template<class OTHER_RET , class FUNC , class ... ARGS>
Context<OTHER_RET>::Ptr Bloomberg::quantum::Context< RET >::postFirst ( int  queueId,
bool  isHighPriority,
FUNC &&  func,
ARGS &&...  args 
)

Posts a coroutine to run asynchronously.

This function is the head of a coroutine continuation chain and must be called only once in the chain.

Template Parameters
OTHER_RETType of future returned by this coroutine.
FUNCCallable object type which will be wrapped in a coroutine. Can be a standalone function, a method, an std::function, a functor generated via std::bind or a lambda. The signature of the callable object must strictly be 'int f(CoroContext<RET>::Ptr, ...)'.
ARGSArgument types passed to FUNC.
Parameters
[in]queueIdId of the queue where this coroutine should run. Note that the user can specify IQueue::QueueId::Any as a value, which is equivalent to running the simpler version of post() above. Valid range is [0, numCoroutineThreads), IQueue::QueueId::Any or IQueue::QueueId::Same. When using IQueue::QueueId::Same as input, the current queueId of this execution context will be preserved for the posted coroutine thus enabling to write lock-free code.
[in]isHighPriorityIf set to true, the coroutine will be scheduled to run immediately after the currently executing coroutine on 'queueId' has completed or has yielded.
[in]funcCallable object.
[in]argsVariable list of arguments passed to the callable object.
Returns
A pointer to a coroutine context object.
Note
This function is non-blocking and returns immediately. The returned context can be used to chain further coroutines. Possible method calls following this are then(), onError(), finally() and end().

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ postFirst() [3/4]

template<class RET>
template<class OTHER_RET , class FUNC , class ... ARGS>
ContextPtr<OTHER_RET> Bloomberg::quantum::Context< RET >::postFirst ( FUNC &&  func,
ARGS &&...  args 
)

Posts a coroutine to run asynchronously.

This function is the head of a coroutine continuation chain and must be called only once in the chain.

Template Parameters
OTHER_RETType of future returned by this coroutine.
FUNCCallable object type which will be wrapped in a coroutine. Can be a standalone function, a method, an std::function, a functor generated via std::bind or a lambda. The signature of the callable object must strictly be 'int f(CoroContext<RET>::Ptr, ...)'.
ARGSArgument types passed to FUNC.
Parameters
[in]funcCallable object.
[in]argsVariable list of arguments passed to the callable object.
Returns
A pointer to a coroutine context object.
Note
This function is non-blocking and returns immediately. The returned context can be used to chain further coroutines. Possible method calls following this are then(), onError(), finally() and end().

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ postFirst() [4/4]

template<class RET>
template<class OTHER_RET , class FUNC , class ... ARGS>
ContextPtr<OTHER_RET> Bloomberg::quantum::Context< RET >::postFirst ( int  queueId,
bool  isHighPriority,
FUNC &&  func,
ARGS &&...  args 
)

Posts a coroutine to run asynchronously.

This function is the head of a coroutine continuation chain and must be called only once in the chain.

Template Parameters
OTHER_RETType of future returned by this coroutine.
FUNCCallable object type which will be wrapped in a coroutine. Can be a standalone function, a method, an std::function, a functor generated via std::bind or a lambda. The signature of the callable object must strictly be 'int f(CoroContext<RET>::Ptr, ...)'.
ARGSArgument types passed to FUNC.
Parameters
[in]queueIdId of the queue where this coroutine should run. Note that the user can specify IQueue::QueueId::Any as a value, which is equivalent to running the simpler version of post() above. Valid range is [0, numCoroutineThreads), IQueue::QueueId::Any or IQueue::QueueId::Same. When using IQueue::QueueId::Same as input, the current queueId of this execution context will be preserved for the posted coroutine thus enabling to write lock-free code.
[in]isHighPriorityIf set to true, the coroutine will be scheduled to run immediately after the currently executing coroutine on 'queueId' has completed or has yielded.
[in]funcCallable object.
[in]argsVariable list of arguments passed to the callable object.
Returns
A pointer to a coroutine context object.
Note
This function is non-blocking and returns immediately. The returned context can be used to chain further coroutines. Possible method calls following this are then(), onError(), finally() and end().

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ postImpl()

template<class RET>
template<class OTHER_RET , class FUNC , class ... ARGS>
ContextPtr<OTHER_RET> Bloomberg::quantum::Context< RET >::postImpl ( int  queueId,
bool  isHighPriority,
ITask::Type  type,
FUNC &&  func,
ARGS &&...  args 
)

◆ pull() [1/2]

template<class RET >
template<class V >
BufferRetType< V > Bloomberg::quantum::Context< RET >::pull ( 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
[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::IThreadContext< RET >.

◆ pull() [2/2]

template<class RET >
template<class V >
BufferRetType< V > Bloomberg::quantum::Context< RET >::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::ICoroContext< RET >.

◆ push() [1/2]

template<class RET >
template<class V , class >
void Bloomberg::quantum::Context< RET >::push ( V &&  value)

Push a single value into the promise buffer.

Template Parameters
BUFRepresents a class of type Buffer.
VThe type of value contained in Buffer.
Parameters
[in]valueValue to push at the end of the buffer.
Note
Method available for buffered futures only. Never blocks. Once the buffer is closed, no more Push operations are allowed.

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ push() [2/2]

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

◆ set() [1/2]

template<class RET >
template<class V , class >
int Bloomberg::quantum::Context< RET >::set ( V &&  value)

Set the promised value associated with this context.

Template Parameters
VType of the promised value. This should be implicitly deduced by the compiler and should always == RET.
Parameters
[in]valueA reference to the value (l-value or r-value).
Note
Never blocks.
Returns
0 on success

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ set() [2/2]

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

◆ setException()

template<class RET >
int Bloomberg::quantum::Context< RET >::setException ( std::exception_ptr  ex)
finalvirtual

Set an exception in the promise associated with the current IThreadContext or ICoroContext.

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::IContextBase.

◆ setTask()

template<class RET >
void Bloomberg::quantum::Context< RET >::setTask ( ITask::Ptr  task)
finalvirtual

◆ setYieldHandle()

template<class RET >
void Bloomberg::quantum::Context< RET >::setYieldHandle ( Traits::Yield yield)
finalvirtual

Sets the underlying boost::coroutine object so that it can be yielded on.

Parameters
[in]yieldReference to the boost::coroutine object.

Implements Bloomberg::quantum::ICoroSync.

◆ signal()

template<class RET >
std::atomic_int & Bloomberg::quantum::Context< RET >::signal ( )
finalvirtual

Accessor to the underlying synchronization variable.

Returns
An atomic integer used to synchronize with other primitive types.

Implements Bloomberg::quantum::ICoroSync.

◆ sleep() [1/2]

template<class RET >
void Bloomberg::quantum::Context< RET >::sleep ( const std::chrono::milliseconds &  timeMs)
finalvirtual

Sleeps the coroutine associated with this context for at least 'timeMs' milliseconds or 'timeUs' microseconds depending on the overload chosen.

Parameters
[in]timeMs/timeUsTime to sleep.
Note
This method yields the coroutine until the timer has expired. Depending on the coroutine load on the particular running thread, this method may sleep longer.

Implements Bloomberg::quantum::ICoroSync.

◆ sleep() [2/2]

template<class RET >
void Bloomberg::quantum::Context< RET >::sleep ( const std::chrono::microseconds &  timeUs)
finalvirtual

◆ terminate()

template<class RET >
void Bloomberg::quantum::Context< RET >::terminate ( )
finalvirtual

Terminates the object.

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

Implements Bloomberg::quantum::ITerminate.

◆ then() [1/2]

template<class RET>
template<class OTHER_RET , class FUNC , class ... ARGS>
Context<OTHER_RET>::Ptr Bloomberg::quantum::Context< RET >::then ( FUNC &&  func,
ARGS &&...  args 
)

Posts a coroutine to run asynchronously.

This function is optional for the continuation chain and may be called 0 or more times. If called, it must follow postFirst() or another then() method.

Template Parameters
OTHER_RETType of future returned by this coroutine.
FUNCCallable object type which will be wrapped in a coroutine. Can be a standalone function, a method, an std::function, a functor generated via std::bind or a lambda. The signature of the callable object must strictly be 'int f(CoroContext<RET>::Ptr, ...)'.
ARGSArgument types passed to FUNC.
Parameters
[in]funcCallable object.
[in]argsVariable list of arguments passed to the callable object.
Returns
A pointer to a coroutine context object.
Note
This function is non-blocking and runs when all previous chained coroutines have completed. The returned context can be used to chain further coroutines. Possible method calls following this are then(), onError(), finally() and end().

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ then() [2/2]

template<class RET>
template<class OTHER_RET , class FUNC , class ... ARGS>
ContextPtr<OTHER_RET> Bloomberg::quantum::Context< RET >::then ( FUNC &&  func,
ARGS &&...  args 
)

Posts a coroutine to run asynchronously.

This function is optional for the continuation chain and may be called 0 or more times. If called, it must follow postFirst() or another then() method.

Template Parameters
OTHER_RETType of future returned by this coroutine.
FUNCCallable object type which will be wrapped in a coroutine. Can be a standalone function, a method, an std::function, a functor generated via std::bind or a lambda. The signature of the callable object must strictly be 'int f(CoroContext<RET>::Ptr, ...)'.
ARGSArgument types passed to FUNC.
Parameters
[in]funcCallable object.
[in]argsVariable list of arguments passed to the callable object.
Returns
A pointer to a coroutine context object.
Note
This function is non-blocking and runs when all previous chained coroutines have completed. The returned context can be used to chain further coroutines. Possible method calls following this are then(), onError(), finally() and end().

Implements Bloomberg::quantum::ICoroContext< RET >.

◆ thenImpl()

template<class RET>
template<class OTHER_RET , class FUNC , class ... ARGS>
ContextPtr<OTHER_RET> Bloomberg::quantum::Context< RET >::thenImpl ( ITask::Type  type,
FUNC &&  func,
ARGS &&...  args 
)

◆ valid()

template<class RET >
bool Bloomberg::quantum::Context< RET >::valid ( ) const
finalvirtual

Determines if the future object associated with this context has a valid shared state with the corresponding promise.

Returns
True if valid, false otherwise.

Implements Bloomberg::quantum::IContextBase.

◆ validAt()

template<class RET >
bool Bloomberg::quantum::Context< RET >::validAt ( int  num) const
finalvirtual

Determines if the future object associated with the 'num'-th continuation context is still valid.

When using coroutine continuations, any future in the continuation chain can be validated using this function. Allowed range for num is [-1, total_continuations). -1 is equivalent of calling valid() or validAt(total_continuations-1) on the last context in the chain (i.e. the context which is returned via IThreadContext::end() or ICoroContext::end()). Position 0 represents the first future in the chain.

Parameters
[in]numThe number indicating which future to validate.
Returns
True if valid, false otherwise.

Implements Bloomberg::quantum::IContextBase.

◆ wait() [1/2]

template<class RET >
void Bloomberg::quantum::Context< RET >::wait ( ) const
finalvirtual

Waits for the future associated with this context to be ready.

Note
Blocks until the future is ready or until an exception is thrown.

Implements Bloomberg::quantum::IThreadContext< RET >.

◆ wait() [2/2]

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

Waits for the future associated with this context to be ready.

Parameters
[in]syncPointer to the coroutine synchronization object.
Note
Blocks until the future is ready or until an exception is thrown.

Implements Bloomberg::quantum::ICoroContextBase.

◆ waitAll() [1/2]

template<class RET >
void Bloomberg::quantum::Context< RET >::waitAll ( ) const
finalvirtual

Wait for all the futures in the continuation chain to be ready.

Note
Blocks until all future values are ready. If any future throws, the exception is swallowed.

Implements Bloomberg::quantum::IThreadContext< RET >.

◆ waitAll() [2/2]

template<class RET >
void Bloomberg::quantum::Context< RET >::waitAll ( ICoroSync::Ptr  sync) const
finalvirtual

Wait for all the futures in the continuation chain to be ready.

Parameters
[in]syncPointer to the coroutine synchronization object.
Note
Blocks until all future values are ready. If any future throws, the exception is swallowed.

Implements Bloomberg::quantum::ICoroContextBase.

◆ waitAt() [1/2]

template<class RET >
void Bloomberg::quantum::Context< RET >::waitAt ( int  num) const
finalvirtual

Waits for the future in the 'num-th' continuation context to be ready.

Allowed range for num is [-1, total_continuations). -1 is equivalent of calling wait() or waitAt(total_continuations-1) on the last context in the chain (i.e. the context which is returned via end()). Position 0 represents the first future in the chain.

Parameters
[in]numThe number indicating which future to wait on.
Note
Blocks until the value is ready or an exception is thrown.

Implements Bloomberg::quantum::IThreadContext< RET >.

◆ waitAt() [2/2]

template<class RET >
void Bloomberg::quantum::Context< RET >::waitAt ( int  num,
ICoroSync::Ptr  sync 
) const
finalvirtual

Waits for the future in the 'num-th' continuation context to be ready.

Allowed range for num is [-1, total_continuations). -1 is equivalent of calling wait() or waitAt(total_continuations-1) on the last context in the chain (i.e. the context which is returned via end()). Position 0 represents the first future in the chain.

Parameters
[in]numThe number indicating which future to wait on.
[in]syncPointer to the coroutine synchronization object.
Note
Blocks until the value is ready or an exception is thrown.

Implements Bloomberg::quantum::ICoroContextBase.

◆ waitFor() [1/2]

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

Waits for the future associated with this context to be ready for a maximum of '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::IThreadContext< RET >.

◆ waitFor() [2/2]

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

Waits for the future associated with this context to be ready for a maximum of 'timeMs' milliseconds.

Parameters
[in]syncPointer to the 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::ICoroContextBase.

◆ waitForAt() [1/2]

template<class RET >
std::future_status Bloomberg::quantum::Context< RET >::waitForAt ( int  num,
std::chrono::milliseconds  timeMs 
) const
finalvirtual

Waits for the future in the 'num-th' continuation context to be ready for a maximum of 'timeMs' milliseconds.

Allowed range for num is [-1, total_continuations). -1 is equivalent of calling wait() or waitAt(total_continuations-1) on the last context in the chain (i.e. the context which is returned via end()). Position 0 represents the first future in the chain.

Parameters
[in]numThe number indicating which future to wait on.
[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::IThreadContext< RET >.

◆ waitForAt() [2/2]

template<class RET >
std::future_status Bloomberg::quantum::Context< RET >::waitForAt ( int  num,
ICoroSync::Ptr  sync,
std::chrono::milliseconds  timeMs 
) const
finalvirtual

Waits for the future in the 'num-th' continuation context to be ready for a maximum of 'timeMs' milliseconds.

Allowed range for num is [-1, total_continuations). -1 is equivalent of calling wait() or waitAt(total_continuations-1) on the last context in the chain (i.e. the context which is returned via end()). Position 0 represents the first future in the chain.

Parameters
[in]numThe number indicating which future to wait on.
[in]syncPointer to the 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::ICoroContextBase.

◆ yield()

template<class RET >
void Bloomberg::quantum::Context< RET >::yield ( )
finalvirtual

Explicitly yields this coroutine context.

Implements Bloomberg::quantum::ICoroSync.

Friends And Related Function Documentation

◆ Context

template<class RET>
template<class OTHER_RET >
friend class Context
friend

◆ Dispatcher

template<class RET>
friend class Dispatcher
friend

◆ Task

template<class RET>
friend class Task
friend

◆ Util

template<class RET>
friend struct Util
friend