Fix stopping of MultiPromiseActor only after and not before it is used again after setting result.
GitOrigin-RevId: 9c7895906911d75b3a8d6077eba113814070df23
This commit is contained in:
parent
f47a287bf8
commit
909dc02b22
@ -10,6 +10,7 @@ namespace td {
|
|||||||
|
|
||||||
void MultiPromiseActor::add_promise(Promise<Unit> &&promise) {
|
void MultiPromiseActor::add_promise(Promise<Unit> &&promise) {
|
||||||
promises_.emplace_back(std::move(promise));
|
promises_.emplace_back(std::move(promise));
|
||||||
|
LOG(DEBUG) << "Add promise #" << promises_.size() << " to " << name_;
|
||||||
}
|
}
|
||||||
|
|
||||||
Promise<Unit> MultiPromiseActor::get_promise() {
|
Promise<Unit> MultiPromiseActor::get_promise() {
|
||||||
@ -24,11 +25,13 @@ Promise<Unit> MultiPromiseActor::get_promise() {
|
|||||||
|
|
||||||
future.set_event(EventCreator::raw(actor_id(), nullptr));
|
future.set_event(EventCreator::raw(actor_id(), nullptr));
|
||||||
futures_.emplace_back(std::move(future));
|
futures_.emplace_back(std::move(future));
|
||||||
|
LOG(DEBUG) << "Get promise #" << futures_.size() << " for " << name_;
|
||||||
return PromiseCreator::from_promise_actor(std::move(promise));
|
return PromiseCreator::from_promise_actor(std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiPromiseActor::raw_event(const Event::Raw &event) {
|
void MultiPromiseActor::raw_event(const Event::Raw &event) {
|
||||||
received_results_++;
|
received_results_++;
|
||||||
|
LOG(DEBUG) << "Receive result #" << received_results_ << " out of " << futures_.size() << " for " << name_;
|
||||||
if (received_results_ == futures_.size()) {
|
if (received_results_ == futures_.size()) {
|
||||||
if (!ignore_errors_) {
|
if (!ignore_errors_) {
|
||||||
for (auto &future : futures_) {
|
for (auto &future : futures_) {
|
||||||
@ -47,13 +50,21 @@ void MultiPromiseActor::set_ignore_errors(bool ignore_errors) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MultiPromiseActor::set_result(Result<Unit> &&result) {
|
void MultiPromiseActor::set_result(Result<Unit> &&result) {
|
||||||
|
result_ = std::move(result);
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MultiPromiseActor::tear_down() {
|
||||||
|
LOG(DEBUG) << "Set result for " << promises_.size() << " promises in " << name_;
|
||||||
|
|
||||||
// MultiPromiseActor should be cleared before it begins to send out result
|
// MultiPromiseActor should be cleared before it begins to send out result
|
||||||
auto promises_copy = std::move(promises_);
|
auto promises_copy = std::move(promises_);
|
||||||
promises_.clear();
|
promises_.clear();
|
||||||
auto futures_copy = std::move(futures_);
|
auto futures_copy = std::move(futures_);
|
||||||
futures_.clear();
|
futures_.clear();
|
||||||
received_results_ = 0;
|
received_results_ = 0;
|
||||||
stop();
|
auto result = std::move(result_);
|
||||||
|
result_ = Unit();
|
||||||
|
|
||||||
if (!promises_copy.empty()) {
|
if (!promises_copy.empty()) {
|
||||||
for (size_t i = 0; i + 1 < promises_copy.size(); i++) {
|
for (size_t i = 0; i + 1 < promises_copy.size(); i++) {
|
||||||
|
@ -77,9 +77,12 @@ class MultiPromiseActor final
|
|||||||
vector<FutureActor<Unit>> futures_; // futures waiting for result of the queries
|
vector<FutureActor<Unit>> futures_; // futures waiting for result of the queries
|
||||||
size_t received_results_ = 0;
|
size_t received_results_ = 0;
|
||||||
bool ignore_errors_ = false;
|
bool ignore_errors_ = false;
|
||||||
|
Result<Unit> result_;
|
||||||
|
|
||||||
void raw_event(const Event::Raw &event) override;
|
void raw_event(const Event::Raw &event) override;
|
||||||
|
|
||||||
|
void tear_down() override;
|
||||||
|
|
||||||
void on_start_migrate(int32) override {
|
void on_start_migrate(int32) override {
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user