diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2025-12-11 21:00:37 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-11 21:00:37 -0600 |
| commit | ff1e28f88e93ba83cf76569b5613445b841efd45 (patch) | |
| tree | 2dc6a20bbd0fa3d038fe0e655d1cf96f0e3bb838 /azalea-client/src | |
| parent | 9bfb1705afb8a48ceace712bc4ee8c0b4d507f49 (diff) | |
| download | azalea-drasl-ff1e28f88e93ba83cf76569b5613445b841efd45.tar.xz | |
Run handler function in a Tokio LocalSet (#295)
* Run handler function in a Tokio LocalSet
* remove tokio flavor=current_thread from examples
* update changelog
Diffstat (limited to 'azalea-client/src')
| -rw-r--r-- | azalea-client/src/client.rs | 10 | ||||
| -rw-r--r-- | azalea-client/src/plugins/tick_counter.rs | 2 |
2 files changed, 9 insertions, 3 deletions
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<dyn std::error::Error>> { /// 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) }); diff --git a/azalea-client/src/plugins/tick_counter.rs b/azalea-client/src/plugins/tick_counter.rs index 9d07991a..43100bba 100644 --- a/azalea-client/src/plugins/tick_counter.rs +++ b/azalea-client/src/plugins/tick_counter.rs @@ -8,7 +8,7 @@ use crate::{mining::MiningSystems, movement::send_position, tick_broadcast::send /// Counts the number of game ticks elapsed on the **local client** since the /// `login` packet was received. -#[derive(Component, Clone, Debug, Default)] +#[derive(Component, Clone, Debug, Default, Eq, PartialEq)] pub struct TicksConnected(pub u64); /// Inserts the counter-increment system into the `GameTick` schedule **before** |
