Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
techleeksnap committed Jul 24, 2024
1 parent 1a4080d commit bf60220
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
11 changes: 2 additions & 9 deletions support-lib/cpp/SharedFuture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@ class SharedFuture {
co_return transform(cpy);
}

// Overload for T = void or `transform` takes no arugment.
template<typename Func, typename = std::enable_if_t<!std::is_invocable_v<Func, const SharedFuture<T>&>>>
SharedFuture<std::remove_cv_t<std::remove_reference_t<std::invoke_result_t<Func>>>> then(Func transform) const {
co_await SharedFuture(*this); // retain copy during coroutine suspension
co_return transform();
}

// -- coroutine support implementation only; not intended externally --

bool await_ready() const {
Expand Down Expand Up @@ -132,8 +125,8 @@ SharedFuture<T>::SharedFuture(Future<T>&& future) {
} else {
sharedStates->storedValue = futureResult.get();
}
} catch (const std::exception& e) {
sharedStates->storedValue = make_unexpected(std::make_exception_ptr(e));
} catch (...) {
sharedStates->storedValue = make_unexpected(std::current_exception());
}
return std::move(sharedStates->coroutineHandles);
}();
Expand Down
6 changes: 3 additions & 3 deletions test-suite/handwritten-src/objc/tests/DBSharedFutureTest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ - (void)testThen

XCTAssertEqual(futureInt.get(), 42);

auto voidFuture = transformedString.then([]() {});
auto voidFuture = transformedString.then([](auto) {});
voidFuture.wait();

auto intFuture2 = voidFuture.then([]() { return 43; });
auto intFuture2 = voidFuture.then([](auto) { return 43; });
XCTAssertEqual(intFuture2.get(), 43);
}

Expand All @@ -72,7 +72,7 @@ - (void)testException

XCTAssertThrows(futureInt.get());

auto thenResult = futureInt.then([]() { return 43; });
auto thenResult = futureInt.then([](const auto& resolved) { return resolved.get(); });
XCTAssertThrows(thenResult.get());

auto withExceptionHandling = futureInt.then([](const auto& resolved) {
Expand Down

0 comments on commit bf60220

Please sign in to comment.