From 6c44a9bb43ed9260aa2edcb2f51dc36b29717839 Mon Sep 17 00:00:00 2001 From: Sergiotarxz Date: Thu, 23 May 2024 17:19:36 +0200 Subject: [PATCH] Improving the main loop. --- lib/TgMagicPdf/PdfBuilder.pm | 2 +- lib/TgMagicPdf/Telegram.pm | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/TgMagicPdf/PdfBuilder.pm b/lib/TgMagicPdf/PdfBuilder.pm index c3abcfa..b135f5e 100644 --- a/lib/TgMagicPdf/PdfBuilder.pm +++ b/lib/TgMagicPdf/PdfBuilder.pm @@ -26,7 +26,7 @@ has _ua => ( is => 'lazy', ); sub _build__ua { my $ua = Mojo::UserAgent->new->with_roles('+Queued'); - $ua->max_active(5); + $ua->max_active(20); $ua->inactivity_timeout(60); return $ua; } diff --git a/lib/TgMagicPdf/Telegram.pm b/lib/TgMagicPdf/Telegram.pm index 7394f0c..7832545 100644 --- a/lib/TgMagicPdf/Telegram.pm +++ b/lib/TgMagicPdf/Telegram.pm @@ -37,6 +37,15 @@ sub run ($self) { } } +sub run_recursive ($self) { + $self->_dispatch_updates.then(sub { + $self->run_recursive; + })->catch(sub ($err) { + warn $err; + $self->run_recursive; + }); +} + sub _dispatch_updates ($self) { my $updates_p = $self->_get_updates; my $promise = Mojo::Promise->new;