diff options
| author | mat <git@matdoes.dev> | 2023-12-04 20:23:41 -0600 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2023-12-04 20:23:41 -0600 |
| commit | da4afa8ae3afec4cd59b9a19ae1e04818f1763a7 (patch) | |
| tree | 15ca61301d19808571ddf7412c732308a17391b1 | |
| parent | 797dd9171088cd697b3c95663cbbc65b05315414 (diff) | |
| download | azalea-drasl-da4afa8ae3afec4cd59b9a19ae1e04818f1763a7.tar.xz | |
simplify boilerplate in examples
| -rwxr-xr-x | azalea/README.md | 12 | ||||
| -rw-r--r-- | azalea/examples/testbot.rs | 24 | ||||
| -rw-r--r-- | azalea/examples/todo/mine_a_chunk.rs | 5 | ||||
| -rw-r--r-- | 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<SS> = /// 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<()> { |
