From da4afa8ae3afec4cd59b9a19ae1e04818f1763a7 Mon Sep 17 00:00:00 2001 From: mat Date: Mon, 4 Dec 2023 20:23:41 -0600 Subject: simplify boilerplate in examples --- azalea/README.md | 12 +++++------- azalea/examples/testbot.rs | 24 +++++++++--------------- azalea/examples/todo/mine_a_chunk.rs | 5 +++-- azalea/src/swarm/mod.rs | 18 ++++++++---------- 4 files changed, 25 insertions(+), 34 deletions(-) diff --git a/azalea/README.md b/azalea/README.md index e9ad121d..37b05084 100755 --- a/azalea/README.md +++ b/azalea/README.md @@ -50,13 +50,11 @@ async fn main() { let account = Account::offline("bot"); // or Account::microsoft("example@example.com").await.unwrap(); - loop { - let e = ClientBuilder::new() - .set_handler(handle) - .start(account.clone(), "localhost") - .await; - eprintln!("{e:?}"); - } + ClientBuilder::new() + .set_handler(handle) + .start(account.clone(), "localhost") + .await + .unwrap(); } #[derive(Default, Clone, Component)] diff --git a/azalea/examples/testbot.rs b/azalea/examples/testbot.rs index aa47d5a2..a304e2ce 100644 --- a/azalea/examples/testbot.rs +++ b/azalea/examples/testbot.rs @@ -21,7 +21,7 @@ struct State {} struct SwarmState {} #[tokio::main] -async fn main() -> anyhow::Result<()> { +async fn main() { { use parking_lot::deadlock; use std::thread; @@ -51,20 +51,14 @@ async fn main() -> anyhow::Result<()> { accounts.push(Account::offline(&format!("bot{i}"))); } - loop { - let e = SwarmBuilder::new() - .add_accounts(accounts.clone()) - .set_handler(handle) - .set_swarm_handler(swarm_handle) - .join_delay(Duration::from_millis(100)) - .start("localhost") - .await; - // let e = azalea::ClientBuilder::new() - // .set_handler(handle) - // .start(Account::offline("bot"), "localhost") - // .await; - eprintln!("{e:?}"); - } + SwarmBuilder::new() + .add_accounts(accounts.clone()) + .set_handler(handle) + .set_swarm_handler(swarm_handle) + .join_delay(Duration::from_millis(100)) + .start("localhost") + .await + .unwrap(); } async fn handle(mut bot: Client, event: Event, _state: State) -> anyhow::Result<()> { diff --git a/azalea/examples/todo/mine_a_chunk.rs b/azalea/examples/todo/mine_a_chunk.rs index 74ffacac..0c439f26 100644 --- a/azalea/examples/todo/mine_a_chunk.rs +++ b/azalea/examples/todo/mine_a_chunk.rs @@ -10,12 +10,13 @@ async fn main() { states.push(State::default()); } - let e = SwarmBuilder::new() + SwarmBuilder::new() .add_accounts(accounts.clone()) .set_handler(handle) .set_swarm_handler(swarm_handle) .start("localhost") - .await; + .await + .unwrap(); } #[derive(Default, Clone, Component)] diff --git a/azalea/src/swarm/mod.rs b/azalea/src/swarm/mod.rs index 5c7a04be..8eb900a1 100644 --- a/azalea/src/swarm/mod.rs +++ b/azalea/src/swarm/mod.rs @@ -470,16 +470,14 @@ pub type BoxSwarmHandleFn = /// states.push(State::default()); /// } /// -/// loop { -/// let e = SwarmBuilder::new() -/// .add_accounts(accounts.clone()) -/// .set_handler(handle) -/// .set_swarm_handler(swarm_handle) -/// .join_delay(Duration::from_millis(1000)) -/// .start("localhost") -/// .await; -/// println!("{e:?}"); -/// } +/// SwarmBuilder::new() +/// .add_accounts(accounts.clone()) +/// .set_handler(handle) +/// .set_swarm_handler(swarm_handle) +/// .join_delay(Duration::from_millis(1000)) +/// .start("localhost") +/// .await +/// .unwrap(); /// } /// /// async fn handle(bot: Client, event: Event, _state: State) -> anyhow::Result<()> { -- cgit v1.2.3