SequenceDispatcher: set error to all NetQueries at tear_down

This commit is contained in:
Arseny Smirnov 2022-01-28 17:43:22 +03:00
parent 452f60be0b
commit c202974d47
2 changed files with 16 additions and 1 deletions

View File

@ -319,7 +319,6 @@ class MultiSequenceDispatcherNewImpl final : public MultiSequenceDispatcherNew {
send_closure(node.callback, &NetQueryCallback::on_result_resendable, std::move(query), std::move(promise));
}
// TODO: without td::Result?
void on_resend(td::Result<NetQueryPtr> query) {
auto task_id = TaskId(get_link_token());
auto &node = *scheduler_.get_task_extra(task_id);
@ -337,6 +336,15 @@ class MultiSequenceDispatcherNewImpl final : public MultiSequenceDispatcherNew {
void loop() override {
flush_pending_queries();
}
void tear_down() override {
// Leaves scheduler_ in an invalid state, but we are closing anyway
scheduler_.for_each([&](Node &node) {
if (node.net_query.empty()) {
return;
}
node.net_query->set_error(Global::request_aborted_error());
});
}
void flush_pending_queries() {
while (true) {

View File

@ -35,6 +35,13 @@ class ChainScheduler {
template <class ExtraTT>
friend td::StringBuilder &operator<<(StringBuilder &sb, ChainScheduler<ExtraTT> &scheduler);
template <class F>
void for_each(F &&f) {
tasks_.for_each([&f](auto, Task &task) {
f(task.extra) ;
});
}
private:
struct ChainNode : ListNode {
TaskId task_id{};