Skip to content

Commit 37ec276

Browse files
author
Alex Damian
authored
Merge pull request #145 from accelerated/promise-constructor
Added support for Promise in the GenericFuture constructor
2 parents 4a90900 + 4dd1121 commit 37ec276

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

quantum/util/impl/quantum_generic_future_impl.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ template <typename T>
6262
GenericFuture<T>::GenericFuture()
6363
{}
6464

65+
template <typename T>
66+
GenericFuture<T>::GenericFuture(const Promise<T>& p) :
67+
_context(local::context() ? p.getICoroFuture() : p.getIThreadFuture())
68+
{}
69+
6570
template <typename T>
6671
GenericFuture<T>::GenericFuture(ThreadContextPtr<T> f) :
6772
_context(f)
@@ -376,6 +381,20 @@ GenericFuture<T>::GenericFuture() :
376381
_threadContext()
377382
{}
378383

384+
template <typename T>
385+
GenericFuture<T>::GenericFuture(const Promise<T>& p) :
386+
_type(local::context() ? Type::CoroFuture : Type::ThreadFuture)
387+
{
388+
if (_type == Type::ThreadFuture)
389+
{
390+
_threadFuture = p.getIThreadFuture();
391+
}
392+
else
393+
{
394+
_coroFuture = p.getICoroFuture();
395+
}
396+
}
397+
379398
template <typename T>
380399
GenericFuture<T>::GenericFuture(ThreadContextPtr<T> f) :
381400
_type(Type::ThreadContext),

quantum/util/quantum_generic_future.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
#ifndef BLOOMBERGLP_QUANTUM_GENERIC_FUTURE_H
1717
#define BLOOMBERGLP_QUANTUM_GENERIC_FUTURE_H
1818

19-
#include <quantum/interface/quantum_ifuture.h>
20-
#include <quantum/interface/quantum_icontext.h>
19+
#include <quantum/quantum_promise.h>
2120
#if (__cplusplus >= 201703L)
2221
#include <variant>
2322
#endif
@@ -39,6 +38,7 @@ class GenericFuture : public IThreadFutureBase
3938
public:
4039
/// @brief Constructors/Destructor
4140
GenericFuture();
41+
GenericFuture(const Promise<T>& p);
4242
GenericFuture(ThreadContextPtr<T> f);
4343
GenericFuture(ThreadFuturePtr<T> f);
4444
GenericFuture(CoroContextPtr<T> f); //uses local context

0 commit comments

Comments
 (0)