Remove rarely used PromiseCreator::lambda with 2 lambdas.

This commit is contained in:
levlam 2022-06-26 17:11:27 +03:00
parent 3dcafdc873
commit f62632fcbc
6 changed files with 46 additions and 43 deletions

View File

@ -77,8 +77,11 @@ void AuthManager::start_up() {
if (state_ == State::LoggingOut) { if (state_ == State::LoggingOut) {
send_log_out_query(); send_log_out_query();
} else if (state_ == State::DestroyingKeys) { } else if (state_ == State::DestroyingKeys) {
G()->net_query_dispatcher().destroy_auth_keys( G()->net_query_dispatcher().destroy_auth_keys(PromiseCreator::lambda([](Result<Unit> result) {
PromiseCreator::lambda([](Unit) { send_closure_later(G()->td(), &Td::destroy); }, PromiseCreator::Ignore())); if (result.is_ok()) {
send_closure_later(G()->td(), &Td::destroy);
}
}));
} }
} }
void AuthManager::tear_down() { void AuthManager::tear_down() {
@ -706,12 +709,15 @@ void AuthManager::destroy_auth_keys() {
return; return;
} }
update_state(State::DestroyingKeys); update_state(State::DestroyingKeys);
auto promise = PromiseCreator::lambda( auto promise = PromiseCreator::lambda([](Result<Unit> result) {
[](Unit) { if (result.is_ok()) {
G()->net_query_dispatcher().destroy_auth_keys(PromiseCreator::lambda( G()->net_query_dispatcher().destroy_auth_keys(PromiseCreator::lambda([](Result<Unit> result) {
[](Unit) { send_closure_later(G()->td(), &Td::destroy); }, PromiseCreator::Ignore())); if (result.is_ok()) {
}, send_closure_later(G()->td(), &Td::destroy);
PromiseCreator::Ignore()); }
}));
}
});
G()->td_db()->get_binlog_pmc()->set("auth", "destroy"); G()->td_db()->get_binlog_pmc()->set("auth", "destroy");
G()->td_db()->get_binlog_pmc()->force_sync(std::move(promise)); G()->td_db()->get_binlog_pmc()->force_sync(std::move(promise));
} }

View File

@ -443,12 +443,12 @@ class DialogDbAsync final : public DialogDbAsyncInterface {
//NB: order is important, destructor of pending_writes_ will change pending_write_results_ //NB: order is important, destructor of pending_writes_ will change pending_write_results_
std::vector<std::pair<Promise<>, Status>> pending_write_results_; std::vector<std::pair<Promise<>, Status>> pending_write_results_;
vector<Promise<>> pending_writes_; vector<Promise<>> pending_writes_; // TODO use Action
double wakeup_at_ = 0; double wakeup_at_ = 0;
template <class F> template <class F>
void add_write_query(F &&f) { void add_write_query(F &&f) {
pending_writes_.push_back(PromiseCreator::lambda(std::forward<F>(f), PromiseCreator::Ignore())); pending_writes_.push_back(PromiseCreator::lambda(std::forward<F>(f)));
if (pending_writes_.size() > MAX_PENDING_QUERIES_COUNT) { if (pending_writes_.size() > MAX_PENDING_QUERIES_COUNT) {
do_flush(); do_flush();
wakeup_at_ = 0; wakeup_at_ = 0;

View File

@ -1216,11 +1216,12 @@ class MessagesDbAsync final : public MessagesDbAsyncInterface {
//NB: order is important, destructor of pending_writes_ will change pending_write_results_ //NB: order is important, destructor of pending_writes_ will change pending_write_results_
vector<std::pair<Promise<>, Status>> pending_write_results_; vector<std::pair<Promise<>, Status>> pending_write_results_;
vector<Promise<>> pending_writes_; vector<Promise<>> pending_writes_; // TODO use Action
double wakeup_at_ = 0; double wakeup_at_ = 0;
template <class F> template <class F>
void add_write_query(F &&f) { void add_write_query(F &&f) {
pending_writes_.push_back(PromiseCreator::lambda(std::forward<F>(f), PromiseCreator::Ignore())); pending_writes_.push_back(PromiseCreator::lambda(std::forward<F>(f)));
if (pending_writes_.size() > MAX_PENDING_QUERIES_COUNT) { if (pending_writes_.size() > MAX_PENDING_QUERIES_COUNT) {
do_flush(); do_flush();
wakeup_at_ = 0; wakeup_at_ = 0;

View File

@ -3212,11 +3212,11 @@ class SendMessageQuery final : public Td::ResultHandler {
{{dialog_id, MessageContentType::Text}, {{dialog_id, MessageContentType::Text},
{dialog_id, is_copy ? MessageContentType::Photo : MessageContentType::Text}}); {dialog_id, is_copy ? MessageContentType::Photo : MessageContentType::Text}});
if (G()->shared_config().get_option_boolean("use_quick_ack")) { if (G()->shared_config().get_option_boolean("use_quick_ack")) {
query->quick_ack_promise_ = PromiseCreator::lambda( query->quick_ack_promise_ = PromiseCreator::lambda([random_id](Result<Unit> result) {
[random_id](Unit) { if (result.is_ok()) {
send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id); send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id);
}, }
PromiseCreator::Ignore()); });
} }
*send_query_ref = query.get_weak(); *send_query_ref = query.get_weak();
send_query(std::move(query)); send_query(std::move(query));
@ -3283,11 +3283,11 @@ class StartBotQuery final : public Td::ResultHandler {
telegram_api::messages_startBot(std::move(bot_input_user), std::move(input_peer), random_id, parameter), telegram_api::messages_startBot(std::move(bot_input_user), std::move(input_peer), random_id, parameter),
{{dialog_id, MessageContentType::Text}, {dialog_id, MessageContentType::Photo}}); {{dialog_id, MessageContentType::Text}, {dialog_id, MessageContentType::Photo}});
if (G()->shared_config().get_option_boolean("use_quick_ack")) { if (G()->shared_config().get_option_boolean("use_quick_ack")) {
query->quick_ack_promise_ = PromiseCreator::lambda( query->quick_ack_promise_ = PromiseCreator::lambda([random_id](Result<Unit> result) {
[random_id](Unit) { if (result.is_ok()) {
send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id); send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id);
}, }
PromiseCreator::Ignore()); });
} }
auto send_query_ref = query.get_weak(); auto send_query_ref = query.get_weak();
send_query(std::move(query)); send_query(std::move(query));
@ -3525,11 +3525,11 @@ class SendMediaQuery final : public Td::ResultHandler {
std::move(reply_markup), std::move(entities), schedule_date, std::move(as_input_peer)), std::move(reply_markup), std::move(entities), schedule_date, std::move(as_input_peer)),
{{dialog_id, content_type}, {dialog_id, is_copy ? MessageContentType::Text : content_type}}); {{dialog_id, content_type}, {dialog_id, is_copy ? MessageContentType::Text : content_type}});
if (G()->shared_config().get_option_boolean("use_quick_ack") && was_uploaded_) { if (G()->shared_config().get_option_boolean("use_quick_ack") && was_uploaded_) {
query->quick_ack_promise_ = PromiseCreator::lambda( query->quick_ack_promise_ = PromiseCreator::lambda([random_id](Result<Unit> result) {
[random_id](Unit) { if (result.is_ok()) {
send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id); send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id);
}, }
PromiseCreator::Ignore()); });
} }
*send_query_ref = query.get_weak(); *send_query_ref = query.get_weak();
send_query(std::move(query)); send_query(std::move(query));
@ -3889,13 +3889,13 @@ class ForwardMessagesQuery final : public Td::ResultHandler {
std::move(random_ids), std::move(to_input_peer), schedule_date, std::move(as_input_peer)), std::move(random_ids), std::move(to_input_peer), schedule_date, std::move(as_input_peer)),
{{to_dialog_id, MessageContentType::Text}, {to_dialog_id, MessageContentType::Photo}}); {{to_dialog_id, MessageContentType::Text}, {to_dialog_id, MessageContentType::Photo}});
if (G()->shared_config().get_option_boolean("use_quick_ack")) { if (G()->shared_config().get_option_boolean("use_quick_ack")) {
query->quick_ack_promise_ = PromiseCreator::lambda( query->quick_ack_promise_ = PromiseCreator::lambda([random_ids = random_ids_](Result<Unit> result) {
[random_ids = random_ids_](Unit) { if (result.is_ok()) {
for (auto random_id : random_ids) { for (auto random_id : random_ids) {
send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id); send_closure(G()->messages_manager(), &MessagesManager::on_send_message_get_quick_ack, random_id);
} }
}, }
PromiseCreator::Ignore()); });
} }
send_query(std::move(query)); send_query(std::move(query));
} }

View File

@ -1436,9 +1436,11 @@ NetQueryPtr SecretChatActor::create_net_query(const log_event::OutboundSecretMes
} }
if (message.is_external && context_->get_config_option_boolean("use_quick_ack")) { if (message.is_external && context_->get_config_option_boolean("use_quick_ack")) {
query->quick_ack_promise_ = query->quick_ack_promise_ =
PromiseCreator::lambda([actor_id = actor_id(this), random_id = message.random_id]( PromiseCreator::lambda([actor_id = actor_id(this), random_id = message.random_id](Result<Unit> result) {
Unit) { send_closure(actor_id, &SecretChatActor::on_send_message_ack, random_id); }, if (result.is_ok()) {
PromiseCreator::Ignore()); send_closure(actor_id, &SecretChatActor::on_send_message_ack, random_id);
}
});
} }
return query; return query;

View File

@ -692,12 +692,6 @@ class PromiseCreator {
return Promise<ArgT>(td::make_unique<detail::LambdaPromise<ArgT, std::decay_t<OkT>>>(std::forward<OkT>(ok))); return Promise<ArgT>(td::make_unique<detail::LambdaPromise<ArgT, std::decay_t<OkT>>>(std::forward<OkT>(ok)));
} }
template <class OkT, class FailT, class ArgT = detail::get_arg_t<OkT>>
static Promise<ArgT> lambda(OkT &&ok, FailT &&fail) {
return Promise<ArgT>(td::make_unique<detail::LambdaPromise<ArgT, std::decay_t<OkT>, std::decay_t<FailT>>>(
std::forward<OkT>(ok), std::forward<FailT>(fail), false));
}
template <class OkT, class ArgT = detail::drop_result_t<detail::get_arg_t<OkT>>> template <class OkT, class ArgT = detail::drop_result_t<detail::get_arg_t<OkT>>>
static auto cancellable_lambda(CancellationToken cancellation_token, OkT &&ok) { static auto cancellable_lambda(CancellationToken cancellation_token, OkT &&ok) {
return Promise<ArgT>(td::make_unique<detail::CancellablePromise<detail::LambdaPromise<ArgT, std::decay_t<OkT>>>>( return Promise<ArgT>(td::make_unique<detail::CancellablePromise<detail::LambdaPromise<ArgT, std::decay_t<OkT>>>>(