From e39de79a6b5913cab2ee59cff492317a24726ba4 Mon Sep 17 00:00:00 2001 From: mat Date: Sat, 18 Nov 2023 00:07:25 -0600 Subject: simplify some code --- azalea/examples/testbot.rs | 7 ++----- azalea/src/swarm/mod.rs | 9 +++++++-- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'azalea') diff --git a/azalea/examples/testbot.rs b/azalea/examples/testbot.rs index 10bb9e4a..a7f34a77 100644 --- a/azalea/examples/testbot.rs +++ b/azalea/examples/testbot.rs @@ -47,7 +47,7 @@ async fn main() -> anyhow::Result<()> { let mut accounts = Vec::new(); - for i in 0..1 { + for i in 0..200 { accounts.push(Account::offline(&format!("bot{i}"))); } @@ -98,10 +98,7 @@ async fn handle(mut bot: Client, event: Event, _state: State) -> anyhow::Result< // .find(|e| e.name() == Some(sender)); // let entity = bot.entity_by::>(|name: &Name| name == sender); let entity = bot.entity_by::, (&GameProfileComponent,)>( - |(profile,): &(&GameProfileComponent,)| { - println!("entity {profile:?}"); - profile.name == sender - }, + |(profile,): &(&GameProfileComponent,)| profile.name == sender, ); println!("sender entity: {entity:?}"); match m.content().as_str() { diff --git a/azalea/src/swarm/mod.rs b/azalea/src/swarm/mod.rs index 1f31db98..585e2608 100644 --- a/azalea/src/swarm/mod.rs +++ b/azalea/src/swarm/mod.rs @@ -393,7 +393,10 @@ where if let Some(handler) = &self.handler { let first_bot_state = first_bot.component::(); let first_bot_entity = first_bot.entity; - tokio::spawn((handler)(first_bot, first_event, first_bot_state.clone())); + + let mut tasks = Vec::new(); + + tasks.push((handler)(first_bot, first_event, first_bot_state.clone())); // this makes it not have to keep locking the ecs let mut states = HashMap::new(); @@ -402,8 +405,10 @@ where let state = states .entry(bot.entity) .or_insert_with(|| bot.component::().clone()); - tokio::spawn((handler)(bot, event, state.clone())); + tasks.push((handler)(bot, event, state.clone())); } + + tokio::spawn(join_all(tasks)); } } -- cgit v1.2.3