From 63d3968f2e756525c8b5884b1d8d611ed3763f2c Mon Sep 17 00:00:00 2001 From: Giuseppe Ottaviano Date: Mon, 18 Sep 2023 09:56:49 -0700 Subject: [PATCH] Fix SharedPromise::setValue() 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 --- folly/experimental/coro/SharedPromise.h | 2 +- .../experimental/coro/test/SharedPromiseTest.cpp | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/folly/experimental/coro/SharedPromise.h b/folly/experimental/coro/SharedPromise.h index 4581cb375fa..07f17601f73 100644 --- a/folly/experimental/coro/SharedPromise.h +++ b/folly/experimental/coro/SharedPromise.h @@ -163,7 +163,7 @@ void SharedPromise::setValue(U&& input) { template template void SharedPromise::setValue() { - setTry({}); + setTry(TryType{unit}); } template diff --git a/folly/experimental/coro/test/SharedPromiseTest.cpp b/folly/experimental/coro/test/SharedPromiseTest.cpp index e36615c20f2..c35173c70bc 100644 --- a/folly/experimental/coro/test/SharedPromiseTest.cpp +++ b/folly/experimental/coro/test/SharedPromiseTest.cpp @@ -289,11 +289,19 @@ TYPED_TEST(SharedPromiseTest, NoHeapAllocation) { } TEST(SharedPromiseTest, BasicVoid) { - auto promise = SharedPromise{}; - auto future = promise.getFuture(); + { + auto promise = SharedPromise{}; + auto future = promise.getFuture(); + + promise.setValue(); + blocking_wait(std::move(future)); + } - promise.setValue(); - blocking_wait(std::move(future)); + { + auto promise = SharedPromise{}; + promise.setValue(); + blocking_wait(promise.getFuture()); + } } #endif