aboutsummaryrefslogtreecommitdiff
path: root/azalea
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-06-14 20:33:22 -1030
committermat <git@matdoes.dev>2025-06-14 20:33:22 -1030
commit5e81d85d7e8eeca1b6c86ea028353d7c55361961 (patch)
tree1cf36f406444811ca39b38af0d874d0ae2351368 /azalea
parenta2606569bb79867d07a075bcf7b05730e4264d72 (diff)
downloadazalea-drasl-5e81d85d7e8eeca1b6c86ea028353d7c55361961.tar.xz
add note about current_thread to azalea readme
Diffstat (limited to 'azalea')
-rw-r--r--azalea/README.md6
-rw-r--r--azalea/examples/echo.rs2
-rw-r--r--azalea/examples/nearest_entity.rs2
-rw-r--r--azalea/examples/steal.rs2
-rw-r--r--azalea/examples/testbot/main.rs4
-rw-r--r--azalea/examples/todo/craft_dig_straight_down.rs5
-rw-r--r--azalea/examples/todo/mine_a_chunk.rs2
-rw-r--r--azalea/examples/todo/pvp.rs10
-rw-r--r--azalea/src/lib.rs2
-rw-r--r--azalea/src/swarm/mod.rs2
10 files changed, 19 insertions, 18 deletions
diff --git a/azalea/README.md b/azalea/README.md
index 26a06dde..4f7506d1 100644
--- a/azalea/README.md
+++ b/azalea/README.md
@@ -46,7 +46,7 @@ use std::sync::Arc;
use azalea::prelude::*;
use parking_lot::Mutex;
-#[tokio::main]
+#[tokio::main(flavor = "current_thread")]
async fn main() {
let account = Account::offline("bot");
// or Account::microsoft("example@example.com").await.unwrap();
@@ -110,5 +110,9 @@ If your code is simply hanging, it might be a deadlock. Enable `parking_lot`'s `
Backtraces are also useful, though they're sometimes hard to read and don't always contain the actual location of the error. Run your code with `RUST_BACKTRACE=1` to enable full backtraces. If it's very long, often searching for the keyword "azalea" will help you filter out unrelated things and find the actual source of the issue.
+# Using a single-threaded Tokio runtime
+
+Due to the fact that Azalea clients store the ECS in a Mutex that's frequently locked and unlocked, bots that rely on the `Client` or `Swarm` types may run into race condition bugs (like out-of-order events and ticks happening at suboptimal moments) if they do not set Tokio to use a single thread with `#[tokio::main(flavor = "current_thread")]`. This may change in a future version of Azalea. Setting this option will usually not result in a performance hit, and Azalea internally will keep using multiple threads for running the ECS itself (because Tokio is not used for this).
+
[`azalea_client`]: https://docs.rs/azalea-client
[`bevy_log`]: https://docs.rs/bevy_log
diff --git a/azalea/examples/echo.rs b/azalea/examples/echo.rs
index 80b0cb15..09c3d5d3 100644
--- a/azalea/examples/echo.rs
+++ b/azalea/examples/echo.rs
@@ -2,7 +2,7 @@
use azalea::prelude::*;
-#[tokio::main]
+#[tokio::main(flavor = "current_thread")]
async fn main() {
let account = Account::offline("bot");
// or let account = Account::microsoft("email").await.unwrap();
diff --git a/azalea/examples/nearest_entity.rs b/azalea/examples/nearest_entity.rs
index 2e6973cf..8774829e 100644
--- a/azalea/examples/nearest_entity.rs
+++ b/azalea/examples/nearest_entity.rs
@@ -12,7 +12,7 @@ use bevy_ecs::{
system::Query,
};
-#[tokio::main]
+#[tokio::main(flavor = "current_thread")]
async fn main() {
let account = Account::offline("bot");
diff --git a/azalea/examples/steal.rs b/azalea/examples/steal.rs
index 899c2568..87a1561b 100644
--- a/azalea/examples/steal.rs
+++ b/azalea/examples/steal.rs
@@ -6,7 +6,7 @@ use azalea::{BlockPos, pathfinder::goals::RadiusGoal, prelude::*};
use azalea_inventory::{ItemStack, operations::QuickMoveClick};
use parking_lot::Mutex;
-#[tokio::main]
+#[tokio::main(flavor = "current_thread")]
async fn main() {
let account = Account::offline("bot");
// or let bot = Account::microsoft("email").await.unwrap();
diff --git a/azalea/examples/testbot/main.rs b/azalea/examples/testbot/main.rs
index 8a35a281..8fb96411 100644
--- a/azalea/examples/testbot/main.rs
+++ b/azalea/examples/testbot/main.rs
@@ -20,8 +20,6 @@
//! only have this on if the bot has operator permissions, otherwise it'll
//! just spam the server console unnecessarily.
-#![feature(trivial_bounds)]
-
mod commands;
pub mod killaura;
@@ -34,7 +32,7 @@ use azalea::{
use commands::{CommandSource, register_commands};
use parking_lot::Mutex;
-#[tokio::main]
+#[tokio::main(flavor = "current_thread")]
async fn main() {
let args = parse_args();
diff --git a/azalea/examples/todo/craft_dig_straight_down.rs b/azalea/examples/todo/craft_dig_straight_down.rs
index 0dc8e16d..bf312331 100644
--- a/azalea/examples/todo/craft_dig_straight_down.rs
+++ b/azalea/examples/todo/craft_dig_straight_down.rs
@@ -1,7 +1,6 @@
use std::sync::Arc;
-use azalea::pathfinder;
-use azalea::prelude::*;
+use azalea::{pathfinder, prelude::*};
use parking_lot::Mutex;
#[derive(Default, Clone, Component)]
@@ -9,7 +8,7 @@ struct State {
pub started: Arc<Mutex<bool>>,
}
-#[tokio::main]
+#[tokio::main(flavor = "current_thread")]
async fn main() {
let account = Account::offline("bot");
// or let bot = Account::microsoft("email").await;
diff --git a/azalea/examples/todo/mine_a_chunk.rs b/azalea/examples/todo/mine_a_chunk.rs
index 0c439f26..eb7fafd4 100644
--- a/azalea/examples/todo/mine_a_chunk.rs
+++ b/azalea/examples/todo/mine_a_chunk.rs
@@ -1,6 +1,6 @@
use azalea::{prelude::*, swarm::prelude::*};
-#[tokio::main]
+#[tokio::main(flavor = "current_thread")]
async fn main() {
let mut accounts = Vec::new();
let mut states = Vec::new();
diff --git a/azalea/examples/todo/pvp.rs b/azalea/examples/todo/pvp.rs
index fb5a768d..0639d86b 100644
--- a/azalea/examples/todo/pvp.rs
+++ b/azalea/examples/todo/pvp.rs
@@ -1,11 +1,11 @@
use std::time::Duration;
-use azalea::ecs::query::With;
-use azalea::entity::metadata::Player;
-use azalea::{pathfinder, Account, Client, Event, GameProfileComponent};
-use azalea::{prelude::*, swarm::prelude::*};
+use azalea::{
+ Account, Client, Event, GameProfileComponent, ecs::query::With, entity::metadata::Player,
+ pathfinder, prelude::*, swarm::prelude::*,
+};
-#[tokio::main]
+#[tokio::main(flavor = "current_thread")]
async fn main() {
let mut accounts = Vec::new();
let mut states = Vec::new();
diff --git a/azalea/src/lib.rs b/azalea/src/lib.rs
index b3e8a7d9..cdf0afbf 100644
--- a/azalea/src/lib.rs
+++ b/azalea/src/lib.rs
@@ -59,7 +59,7 @@ pub enum StartError {
///
/// ```no_run
/// # use azalea::prelude::*;
-/// # #[tokio::main]
+/// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() {
/// ClientBuilder::new()
/// .set_handler(handle)
diff --git a/azalea/src/swarm/mod.rs b/azalea/src/swarm/mod.rs
index 35007b9e..ff85e2c1 100644
--- a/azalea/src/swarm/mod.rs
+++ b/azalea/src/swarm/mod.rs
@@ -636,7 +636,7 @@ pub type BoxSwarmHandleFn<SS, R> =
/// #[derive(Default, Clone, Resource)]
/// struct SwarmState {}
///
-/// #[tokio::main]
+/// #[tokio::main(flavor = "current_thread")]
/// async fn main() {
/// let mut accounts = Vec::new();
/// let mut states = Vec::new();