Skip to content

Commit

Permalink
Merge pull request #99 from FelixPetriconi/Fix18
Browse files Browse the repository at this point in the history
Remove comment after clarification and add test case for this.
  • Loading branch information
FelixPetriconi authored Nov 14, 2017
2 parents 73d98ae + 8963117 commit 6ad2c41
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
5 changes: 0 additions & 5 deletions stlab/concurrency/future.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,11 +656,6 @@ class future<T, enable_if_copyable<T>> {
return _p->get_try();
}

// Fp Does it make sense to have this? At the moment I don't see a real use case for it.
// One can only ask once on an r-value and then the future is gone.
// To perform this in an l-value casted to an r-value does not make sense either,
// because in this case _p is not unique any more and internally it is forwarded to
// the l-value get_try.
auto get_try() && {
return _p->get_try_r(_p.unique());
}
Expand Down
27 changes: 26 additions & 1 deletion test/future_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,29 @@ BOOST_AUTO_TEST_CASE(future_swap_tests)
BOOST_REQUIRE_EQUAL(5, a.second.get_try().value().member());
BOOST_REQUIRE_EQUAL(4, b.second.get_try().value().member());
}
}
}

BOOST_FIXTURE_TEST_SUITE(future_then_void, test_fixture<int>)

BOOST_AUTO_TEST_CASE(future_get_try_refref) {
BOOST_TEST_MESSAGE("future get_try()&& accessor test");

auto sut = async(default_executor, [] { return 42; })
.then([](int val) {
throw test_exception("failure");
return 0;
})
.recover([](auto &&f) {
try {
std::forward<decltype(f)>(f).get_try();
return 0;
}
catch (const test_exception &e) {
return 42;
}
});

wait_until_future_completed(sut);
BOOST_REQUIRE_EQUAL(42, sut.get_try().value());
}
BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 6ad2c41

Please sign in to comment.