16 #ifndef BLOOMBERG_QUANTUM_ITHREAD_CONTEXT_H 17 #define BLOOMBERG_QUANTUM_ITHREAD_CONTEXT_H 21 #include <quantum/quantum_traits.h> 22 #include <quantum/interface/quantum_ithread_context_base.h> 40 using Ptr = std::shared_ptr<IThreadContext<RET>>;
45 virtual void wait()
const = 0;
51 virtual std::future_status
waitFor(std::chrono::milliseconds timeMs)
const = 0;
59 virtual void waitAt(
int num)
const = 0;
69 virtual std::future_status
waitForAt(
int num, std::chrono::milliseconds timeMs)
const = 0;
73 virtual void waitAll()
const = 0;
78 template <
class V = RET>
85 template <
class V = RET>
97 template <
class OTHER_RET>
109 template <
class OTHER_RET>
117 template <
class V,
class = NonBufferType<RET,V>>
126 template <
class V,
class = BufferType<RET,V>>
127 void push(V&& value);
135 template <
class V = RET>
143 template <
class V = RET,
class = BufferRetType<V>>
190 template <
class OTHER_RET = int,
class FUNC,
class ... ARGS>
192 then(FUNC&& func, ARGS&&... args);
210 template <
class OTHER_RET = int,
class FUNC,
class ... ARGS>
212 onError(FUNC&& func, ARGS&&... args);
226 template <
class OTHER_RET = int,
class FUNC,
class ... ARGS>
228 finally(FUNC&& func, ARGS&&... args);
246 #endif //BLOOMBERG_QUANTUM_ITHREAD_CONTEXT_H Definition: quantum_buffer_impl.h:22
int getNumIoThreads() const
Returns the number of underlying IO threads as specified in the dispatcher constructor.
Definition: quantum_context_impl.h:92
std::shared_ptr< IContextBase > Ptr
Definition: quantum_icontext_base.h:35
virtual std::future_status waitFor(std::chrono::milliseconds timeMs) const =0
Waits for the future associated with this context to be ready for a maximum of 'timeMs' milliseconds.
virtual void waitAll() const =0
Wait for all the futures in the continuation chain to be ready.
virtual std::future_status waitForAt(int num, std::chrono::milliseconds timeMs) const =0
Waits for the future in the 'num-th' continuation context to be ready for a maximum of 'timeMs' milli...
const NonBufferRetType< OTHER_RET > & getRefAt(int num) const
Get a reference to the future value from the 'num-th' continuation context.
Definition: quantum_context_impl.h:52
const NonBufferRetType< V > & getRef() const
Get a reference the future value associated with this context.
Definition: quantum_context_impl.h:38
std::shared_ptr< IThreadContext< RET > > Ptr
Definition: quantum_ithread_context.h:40
Exposes methods to manipulate the thread context, especially future wait methods.
Definition: quantum_ithread_context_base.h:34
int closeBuffer()
Close a promise buffer.
Definition: quantum_context_impl.h:80
std::enable_if_t<!Traits::IsBuffer< T >::value, typename Traits::IsBuffer< T >::Type > NonBufferRetType
Definition: quantum_traits.h:95
const std::pair< int, int > & getCoroQueueIdRangeForAny() const
Gets the range [minQueueId, maxQueueId] of coroutine queueIds covered by IQueue::QueueId::Any by the ...
Definition: quantum_context_impl.h:98
virtual void waitAt(int num) const =0
Waits for the future in the 'num-th' continuation context to be ready.
Concrete class representing a coroutine or a thread context.
Definition: quantum_icoro_context.h:29
NonBufferRetType< V > get()
Get the future value associated with this context.
Definition: quantum_context_impl.h:31
IThreadContext< OTHER_RET >::Ptr then(FUNC &&func, ARGS &&... args)
Posts a function to run asynchronously.
virtual void wait() const =0
Waits for the future associated with this context to be ready.
Definition: quantum_icontext_base.h:26
void push(V &&value)
Push a single value into the promise buffer.
Definition: quantum_context_impl.h:66
NonBufferRetType< OTHER_RET > getAt(int num)
Get the future value from the 'num-th' continuation context.
Definition: quantum_context_impl.h:45
int set(V &&value)
Set the promised value associated with this context.
Definition: quantum_context_impl.h:59
IThreadContext< OTHER_RET >::Ptr onError(FUNC &&func, ARGS &&... args)
Posts a function to run asynchronously. This is the error handler for a continuation chain and acts a...
std::enable_if_t< Traits::IsBuffer< T >::value, typename Traits::IsBuffer< T >::Type > BufferRetType
Definition: quantum_traits.h:93
Exposes methods to manipulate the thread context.
Definition: quantum_ithread_context.h:37
Ptr end()
This is the last method in a continuation chain.
Definition: quantum_context_impl.h:129
int getNumCoroutineThreads() const
Returns the number of underlying coroutine threads as specified in the dispatcher constructor....
Definition: quantum_context_impl.h:86
typename IThreadContext< RET >::Ptr ThreadContextPtr
Definition: quantum_ithread_context.h:242
BufferRetType< V > pull(bool &isBufferClosed)
Pull a single value from the future buffer.
Definition: quantum_context_impl.h:73