From cd3dcc161115c8ed6c9acb7f948f1f756d9e03af Mon Sep 17 00:00:00 2001 From: Lewis Pearson Date: Mon, 21 Oct 2024 19:39:26 -0400 Subject: [PATCH] Write a clarifying comment on Tokio's stack size --- crates/teloxide/src/dispatching/dispatcher.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/teloxide/src/dispatching/dispatcher.rs b/crates/teloxide/src/dispatching/dispatcher.rs index d70cd3eb..56dc5f6e 100644 --- a/crates/teloxide/src/dispatching/dispatcher.rs +++ b/crates/teloxide/src/dispatching/dispatcher.rs @@ -410,7 +410,12 @@ where let stop_token = Some(update_listener.stop_token()); - std::thread::scope(|scope| { + // We create a new Tokio runtime in order to set the correct stack size. We do + // it a scoped thread because Tokio runtimes cannot be nested. We need a scoped + // thread because of the lifetime `'a` in `&'a mut self` and because scoped + // threads are automatically joined. See this issue: + // . + std::thread::scope(|scope: &std::thread::Scope<'_, '_>| { scope.spawn(move || { let runtime = tokio::runtime::Builder::new_multi_thread() .thread_stack_size(self.stack_size)