diff --git a/src/core/lib/promise/sleep.h b/src/core/lib/promise/sleep.h index 5fe735f27bf..7f3a9685230 100644 --- a/src/core/lib/promise/sleep.h +++ b/src/core/lib/promise/sleep.h @@ -18,11 +18,11 @@ #include #include +#include #include "absl/status/status.h" #include -#include #include "src/core/lib/gprpp/time.h" #include "src/core/lib/promise/activity.h" @@ -38,17 +38,12 @@ class Sleep final { Sleep(const Sleep&) = delete; Sleep& operator=(const Sleep&) = delete; - Sleep(Sleep&& other) noexcept : deadline_(other.deadline_) { - // Promises can be moved only until they're polled, and since we only create - // the closure when first polled we can assume it's nullptr here. - GPR_DEBUG_ASSERT(other.closure_ == nullptr); - }; + Sleep(Sleep&& other) noexcept + : deadline_(other.deadline_), + closure_(std::exchange(other.closure_, nullptr)) {} Sleep& operator=(Sleep&& other) noexcept { - // Promises can be moved only until they're polled, and since we only create - // the closure when first polled we can assume it's nullptr here. - GPR_DEBUG_ASSERT(closure_ == nullptr); - GPR_DEBUG_ASSERT(other.closure_ == nullptr); deadline_ = other.deadline_; + std::swap(closure_, other.closure_); return *this; }; diff --git a/test/core/promise/BUILD b/test/core/promise/BUILD index f34b1d68b4c..620c40a2c65 100644 --- a/test/core/promise/BUILD +++ b/test/core/promise/BUILD @@ -501,6 +501,7 @@ grpc_cc_test( deps = [ "test_wakeup_schedulers", "//:exec_ctx", + "//:gpr", "//:grpc", "//src/core:default_event_engine", "//src/core:exec_ctx_wakeup_scheduler", diff --git a/test/core/promise/sleep_test.cc b/test/core/promise/sleep_test.cc index 197f5966336..ac8abcec64f 100644 --- a/test/core/promise/sleep_test.cc +++ b/test/core/promise/sleep_test.cc @@ -24,6 +24,7 @@ #include "gtest/gtest.h" #include +#include #include "src/core/lib/event_engine/default_event_engine.h" #include "src/core/lib/gprpp/notification.h"