From ff1e28f88e93ba83cf76569b5613445b841efd45 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Thu, 11 Dec 2025 21:00:37 -0600 Subject: Run handler function in a Tokio LocalSet (#295) * Run handler function in a Tokio LocalSet * remove tokio flavor=current_thread from examples * update changelog --- azalea-client/src/client.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'azalea-client/src/client.rs') diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs index 439f4d29..18a54125 100644 --- a/azalea-client/src/client.rs +++ b/azalea-client/src/client.rs @@ -158,7 +158,7 @@ impl Client { /// ```rust,no_run /// use azalea_client::{Account, Client}; /// - /// #[tokio::main(flavor = "current_thread")] + /// #[tokio::main] /// async fn main() -> Result<(), Box> { /// let account = Account::offline("bot"); /// let (client, rx) = Client::join(account, "localhost").await?; @@ -587,6 +587,12 @@ impl Plugin for AzaleaPlugin { /// /// You can create your app with `App::new()`, but don't forget to add /// [`DefaultPlugins`]. +/// +/// # Panics +/// +/// This function panics if it's called outside of a Tokio `LocalSet` (or +/// `LocalRuntime`). This exists so Azalea doesn't unexpectedly run game ticks +/// in the middle of blocking user code. #[doc(hidden)] pub fn start_ecs_runner( app: &mut SubApp, @@ -615,7 +621,7 @@ pub fn start_ecs_runner( let (appexit_tx, appexit_rx) = oneshot::channel(); let start_running_systems = move || { - tokio::spawn(async move { + tokio::task::spawn_local(async move { let appexit = run_schedule_loop(ecs_clone, outer_schedule_label).await; appexit_tx.send(appexit) }); -- cgit v1.2.3