Skip to content

Commit

Permalink
simplify boilerplate in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-1 committed Dec 5, 2023
1 parent 797dd91 commit da4afa8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 34 deletions.
12 changes: 5 additions & 7 deletions azalea/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,11 @@ async fn main() {
let account = Account::offline("bot");
// or Account::microsoft("[email protected]").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)]
Expand Down
24 changes: 9 additions & 15 deletions azalea/examples/testbot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<()> {
Expand Down
5 changes: 3 additions & 2 deletions azalea/examples/todo/mine_a_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
18 changes: 8 additions & 10 deletions azalea/src/swarm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand Down

0 comments on commit da4afa8

Please sign in to comment.