1use futures::future::{self, FutureExt};
2use futures::stream::StreamExt;
3use irc_async::{Client, ClientError, Config};
4
5type Result<T> = std::result::Result<T, ClientError>;
6
7async fn run() -> Result<()> {
8 let config = Config {
9 host: "127.0.0.1".into(),
10 port: 4444,
11 ssl: false,
12 nick: "hello".into(),
13 };
14 let (mut client, fut) = Client::with_config(config).await?;
15 client.register().await?;
16
17 let handler = async {
18 while let Some(Ok(message)) = client.next().await {
19 println!("message: {:?}", message);
20 client.send(message).await.unwrap();
21 }
22 };
23
24 future::join(fut, handler).map(|(first, _)| first).await?;
25
26 Ok(())
27}
28
29#[tokio::main]
30async fn main() {
31 if let Err(err) = run().await {
32 eprintln!("err: {:?}", err);
33 }
34}