QuantumLibrary
quantum_ithread_promise.h
1 /*
2 ** Copyright 2018 Bloomberg Finance L.P.
3 **
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
7 **
8 ** http://www.apache.org/licenses/LICENSE-2.0
9 **
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 */
16 #ifndef BLOOMBERG_QUANTUM_ITHREAD_PROMISE_H
17 #define BLOOMBERG_QUANTUM_ITHREAD_PROMISE_H
18 
19 #include <quantum/interface/quantum_icontext_base.h>
20 #include <quantum/interface/quantum_ipromise_base.h>
21 #include <quantum/interface/quantum_ifuture.h>
22 
23 namespace Bloomberg {
24 namespace quantum {
25 
26 //==============================================================================================
27 // interface IThreadPromise
28 //==============================================================================================
33 template <template<class> class PROMISE, class T>
34 struct IThreadPromise : public Traits::DerivedFrom<PROMISE<T>,
35  IThreadPromise<PROMISE, T>,
36  IPromiseBase>
37 {
39  using Ptr = std::shared_ptr<IThreadPromise<PROMISE, T>>;
40  using Impl = PROMISE<T>;
41 
45  IThreadPromise(Impl* derived){ UNUSED(derived); }
46 
49  virtual ThreadFuturePtr<T> getIThreadFuture() const = 0;
50 
55  template <class V, class = NonBufferType<T,V>>
56  int set(V&& value);
57 
64  template <class V, class = BufferType<T,V>>
65  void push(V&& value);
66 
72  template <class V = T, class = BufferRetType<V>>
73  int closeBuffer();
74 };
75 
76 template <class T> class Promise;
77 
78 template <class T>
80 
81 template <class T>
83 
84 }}
85 
86 #endif //BLOOMBERG_QUANTUM_ITHREAD_PROMISE_H
typename IThreadPromise< Promise, T >::Ptr ThreadPromisePtr
Definition: quantum_ithread_promise.h:82
Definition: quantum_buffer_impl.h:22
int closeBuffer()
Close a promise buffer.
Definition: quantum_promise_impl.h:45
Definition: quantum_traits.h:78
void push(V &&value)
Push a single value into the promise buffer.
Definition: quantum_promise_impl.h:38
Class representing a promised value.
Definition: quantum_icoro_promise.h:77
IThreadPromise(Impl *derived)
Constructor.
Definition: quantum_ithread_promise.h:45
Exposes methods to access and manipulate a non-coroutine promise (i.e. used in a thread)
Definition: quantum_ithread_promise.h:34
Definition: quantum_icontext_base.h:26
std::shared_ptr< IThreadPromise< Promise, T > > Ptr
Definition: quantum_ithread_promise.h:39
virtual ThreadFuturePtr< T > getIThreadFuture() const =0
Get the associated thread future.
typename IThreadFuture< T >::Ptr ThreadFuturePtr
Definition: quantum_ithread_future.h:69
int set(V &&value)
Set the promised value.
Definition: quantum_promise_impl.h:31