QuantumLibrary
quantum_icoro_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_ICORO_PROMISE_H
17 #define BLOOMBERG_QUANTUM_ICORO_PROMISE_H
18 
19 #include <quantum/interface/quantum_icontext_base.h>
20 #include <quantum/interface/quantum_ipromise_base.h>
21 
22 namespace Bloomberg {
23 namespace quantum {
24 
25 //==============================================================================================
26 // interface ICoroPromise
27 //==============================================================================================
32 template <template<class> class PROMISE, class T>
33 struct ICoroPromise : public Traits::DerivedFrom<PROMISE<T>,
34  ICoroPromise<PROMISE, T>,
35  IPromiseBase>
36 {
38  using Ptr = std::shared_ptr<ICoroPromise<PROMISE, T>>;
39  using Impl = PROMISE<T>;
40 
44  ICoroPromise(Impl* derived){ UNUSED(derived); }
45 
48  virtual CoroFuturePtr<T> getICoroFuture() const = 0;
49 
55  template <class V, class = NonBufferType<T,V>>
56  int set(ICoroSync::Ptr sync, V&& value);
57 
65  template <class V, class = BufferType<T,V>>
66  void push(ICoroSync::Ptr sync, V&& value);
67 
73  template <class V = T, class = BufferRetType<V>>
74  int closeBuffer();
75 };
76 
77 template <class T> class Promise;
78 
79 template <class T>
81 
82 template <class T>
84 
85 }}
86 
87 #endif //BLOOMBERG_QUANTUM_ICORO_PROMISE_H
Definition: quantum_buffer_impl.h:22
typename ICoroFuture< T >::Ptr CoroFuturePtr
Definition: quantum_icoro_future.h:72
int set(ICoroSync::Ptr sync, V &&value)
Set the promised value.
Definition: quantum_promise_impl.h:55
Definition: quantum_traits.h:78
typename ICoroPromise< Promise, T >::Ptr CoroPromisePtr
Definition: quantum_icoro_promise.h:83
std::shared_ptr< ICoroSync > Ptr
Definition: quantum_icoro_sync.h:36
virtual CoroFuturePtr< T > getICoroFuture() const =0
Get the associated coroutine future.
Class representing a promised value.
Definition: quantum_icoro_promise.h:77
std::shared_ptr< ICoroPromise< Promise, T > > Ptr
Definition: quantum_icoro_promise.h:38
ICoroPromise(Impl *derived)
Constructor.
Definition: quantum_icoro_promise.h:44
Exposes methods to access and manipulate a coroutine-compatible promise.
Definition: quantum_icoro_promise.h:33
int closeBuffer()
Close a promise buffer.
Definition: quantum_promise_impl.h:69
void push(ICoroSync::Ptr sync, V &&value)
Push a single value into the promise buffer.
Definition: quantum_promise_impl.h:62
Definition: quantum_icontext_base.h:25