How can I make dispatching concurrent? #773
-
So, with Teloxide 0.11.1, I have this code: use teloxide::prelude::*;
#[tokio::main]
async fn main() {
let bot = Bot::from_env();
let handler = Update::filter_message().endpoint(
|bot: Bot, msg: Message| async move {
bot.send_message(msg.chat.id, "A").await?;
tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
bot.send_message(msg.chat.id, "B").await?;
respond(())
},
);
Dispatcher::builder(bot, handler)
.enable_ctrlc_handler()
.build().dispatch().await;
} From everything being However, that seems to not be the case: it sends "A", then waits 3 seconds, sends "B", then sends "A" immediately after, and sends "B" after another 3 seconds. I don't know if this behavior is present with Is there a way to achieve this same behavior, but have the endpoint closure be run concurrently? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
From the
Because you communicate with your bot in the same chat, all your updates are handled sequentially, which works as designed. If you want to override this behaviour, you can do it through aforestated |
Beta Was this translation helpful? Give feedback.
From the
Dispatcher
documentation:Because you communicate with your bot in the same chat, all your updates are handled sequentially, which works as designed. If you want to override this behaviour, you can do it through aforestated
distribution_function
. In particular, if you want all updates to be handled concurrently, just returnNone
from this function.