diff --git a/td/telegram/RequestActor.h b/td/telegram/RequestActor.h index 9e1e8f82f..f32a76242 100644 --- a/td/telegram/RequestActor.h +++ b/td/telegram/RequestActor.h @@ -30,13 +30,15 @@ class RequestActor : public Actor { } void loop() override { - PromiseActor promise; + PromiseActor promise_actor; FutureActor future; - init_promise_future(&promise, &future); + init_promise_future(&promise_actor, &future); - do_run(PromiseCreator::from_promise_actor(std::move(promise))); + auto promise = PromiseCreator::from_promise_actor(std::move(promise_actor)); + do_run(std::move(promise)); if (future.is_ready()) { + CHECK(!promise); if (future.is_error()) { do_send_error(future.move_as_error()); } else { @@ -45,6 +47,9 @@ class RequestActor : public Actor { } stop(); } else { + LOG_CHECK(!promise.was_set_value) << future.empty() << " " << future.get_state(); + CHECK(!future.empty()); + CHECK(future.get_state() == FutureActor::State::Waiting); if (--tries_left_ == 0) { future.close(); do_send_error(Status::Error(400, "Requested data is inaccessible")); diff --git a/tdactor/td/actor/PromiseFuture.h b/tdactor/td/actor/PromiseFuture.h index a8527d7d0..bd3f4b805 100644 --- a/tdactor/td/actor/PromiseFuture.h +++ b/tdactor/td/actor/PromiseFuture.h @@ -62,10 +62,12 @@ class SafePromise; template class Promise { public: + bool was_set_value{false}; void set_value(T &&value) { if (!promise_) { return; } + was_set_value = true; promise_->set_value(std::move(value)); promise_.reset(); } @@ -73,6 +75,7 @@ class Promise { if (!promise_) { return; } + was_set_value = true; promise_->set_error(std::move(error)); promise_.reset(); } @@ -80,6 +83,7 @@ class Promise { if (!promise_) { return; } + was_set_value = true; promise_->set_result(std::move(result)); promise_.reset(); } @@ -404,9 +408,9 @@ class PromiseActor final : public PromiseInterface { template class FutureActor final : public Actor { friend class PromiseActor; + public: enum State { Waiting, Ready }; - public: static constexpr int Hangup = 426487; FutureActor() = default; @@ -457,6 +461,10 @@ class FutureActor final : public Actor { } } + State get_state() const { + return state_; + } + template friend void init_promise_future(PromiseActor *promise, FutureActor *future);