Skip to content

Commit

Permalink
Fix SharedPromise<void>::setValue()
Browse files Browse the repository at this point in the history
Summary: `setValue()` incorrectly leaves `result` unfulfilled, since a default-constructed `Try` doesn't have either a value or an exception, so any futures constructed after the `SharedPromise` is fulfilled are never fulfilled.

Reviewed By: ispeters

Differential Revision: D49373014

fbshipit-source-id: 6cd890863c9a0e4c65eab71a3b24bb760f057f91
  • Loading branch information
ot authored and facebook-github-bot committed Sep 18, 2023
1 parent 6c2234c commit 63d3968
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion folly/experimental/coro/SharedPromise.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void SharedPromise<T>::setValue(U&& input) {
template <typename T>
template <typename U, typename>
void SharedPromise<T>::setValue() {
setTry({});
setTry(TryType{unit});
}

template <typename T>
Expand Down
16 changes: 12 additions & 4 deletions folly/experimental/coro/test/SharedPromiseTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,19 @@ TYPED_TEST(SharedPromiseTest, NoHeapAllocation) {
}

TEST(SharedPromiseTest, BasicVoid) {
auto promise = SharedPromise<void>{};
auto future = promise.getFuture();
{
auto promise = SharedPromise<void>{};
auto future = promise.getFuture();

promise.setValue();
blocking_wait(std::move(future));
}

promise.setValue();
blocking_wait(std::move(future));
{
auto promise = SharedPromise<void>{};
promise.setValue();
blocking_wait(promise.getFuture());
}
}

#endif

0 comments on commit 63d3968

Please sign in to comment.