RequestActor: add checks

GitOrigin-RevId: 16b850d775030948afcaea79695e5961d9652c70
This commit is contained in:
Arseny Smirnov 2020-03-27 14:37:33 +03:00
parent a0a446f987
commit 36cc950820
2 changed files with 17 additions and 4 deletions

View File

@ -30,13 +30,15 @@ class RequestActor : public Actor {
}
void loop() override {
PromiseActor<T> promise;
PromiseActor<T> promise_actor;
FutureActor<T> 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<T>::State::Waiting);
if (--tries_left_ == 0) {
future.close();
do_send_error(Status::Error(400, "Requested data is inaccessible"));

View File

@ -62,10 +62,12 @@ class SafePromise;
template <class T = Unit>
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<T> {
template <class T>
class FutureActor final : public Actor {
friend class PromiseActor<T>;
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 <class S>
friend void init_promise_future(PromiseActor<S> *promise, FutureActor<S> *future);