You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2017/11/20 00:32:23 UTC
mesos git commit: Added a Future constructor for Try>.
Repository: mesos
Updated Branches:
refs/heads/master 2939c86a5 -> 178f59f77
Added a Future constructor for Try<Future<T>>.
Longer term we may want to figure out an alternative "flattening"
strategy, but for now the approach has been to add constructors
that allow flattening.
Review: https://reviews.apache.org/r/63940
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/178f59f7
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/178f59f7
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/178f59f7
Branch: refs/heads/master
Commit: 178f59f773dfaab25d51fe5a5f71be16027a09da
Parents: 2939c86
Author: Benjamin Mahler <bm...@apache.org>
Authored: Sun Nov 19 16:18:25 2017 -0800
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Sun Nov 19 16:20:54 2017 -0800
----------------------------------------------------------------------
3rdparty/libprocess/include/process/future.hpp | 12 ++++++++++
3rdparty/libprocess/src/tests/future_tests.cpp | 25 +++++++++++++++++++++
2 files changed, 37 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/178f59f7/3rdparty/libprocess/include/process/future.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/future.hpp b/3rdparty/libprocess/include/process/future.hpp
index 4cf44ba..1b07bf9 100644
--- a/3rdparty/libprocess/include/process/future.hpp
+++ b/3rdparty/libprocess/include/process/future.hpp
@@ -108,6 +108,8 @@ public:
/*implicit*/ Future(const Try<T>& t);
+ /*implicit*/ Future(const Try<Future<T>>& t);
+
~Future() = default;
// Futures are assignable (and copyable). This results in the
@@ -997,6 +999,16 @@ Future<T>::Future(const Try<T>& t)
template <typename T>
+Future<T>::Future(const Try<Future<T>>& t)
+ : data(t.isSome() ? t->data : std::shared_ptr<Data>(new Data()))
+{
+ if (!t.isSome()) {
+ fail(t.error());
+ }
+}
+
+
+template <typename T>
Future<T>& Future<T>::operator=(const Future<T>& that)
{
if (this != &that) {
http://git-wip-us.apache.org/repos/asf/mesos/blob/178f59f7/3rdparty/libprocess/src/tests/future_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/future_tests.cpp b/3rdparty/libprocess/src/tests/future_tests.cpp
index 76a32bd..77529ec 100644
--- a/3rdparty/libprocess/src/tests/future_tests.cpp
+++ b/3rdparty/libprocess/src/tests/future_tests.cpp
@@ -541,6 +541,31 @@ TEST(FutureTest, FromTry)
}
+TEST(FutureTest, FromTryFuture)
+{
+ Try<Future<int>> t = 1;
+ Future<int> future = t;
+
+ ASSERT_TRUE(future.isReady());
+ EXPECT_EQ(1, future.get());
+
+ Promise<int> p;
+ t = p.future();
+ future = t;
+
+ ASSERT_TRUE(future.isPending());
+ p.set(1);
+ ASSERT_TRUE(future.isReady());
+ EXPECT_EQ(1, future.get());
+
+ t = Error("error");
+ future = t;
+
+ ASSERT_TRUE(future.isFailed());
+ EXPECT_EQ(t.error(), future.failure());
+}
+
+
TEST(FutureTest, ArrowOperator)
{
Future<string> s = string("hello");