1use async_std::{io, task};
2use simple_message_channels::{Message, Writer};
3
4fn main() {
5 task::block_on(async move { send().await.unwrap() });
6}
7
8async fn send() -> io::Result<()> {
9 let stdout = io::stdout().lock().await;
10 let mut writer = Writer::new(stdout);
11 for i in 0..3 {
12 let message = Message::new(i, 1, "hi".as_bytes().to_vec());
13 print_msg(&message);
14 writer.send(message).await?;
15 }
16 Ok(())
17}
18
19fn print_msg(msg: &Message) {
20 let text = String::from_utf8(msg.message.clone()).unwrap();
21 eprintln!("send: ch {} typ {}: {}", msg.channel, msg.typ, text);
22}