Might be a noob question, I'm learning Rust.
When using tokio::time::sleep to delay each send_privmsg, it sends them all at once instead of sending one, then delaying, then sending one, etc.
Here is a reporducing example, where you can see all message got sent at once after waiting for 5 seconds.
use futures::prelude::*;
use irc::client::prelude::*;
use tokio::time::{sleep, Duration};
#[tokio::main]
async fn main() -> irc::error::Result<()> {
let config = Config {
[...]
};
let mut client = Client::from_config(config).await?;
client.identify()?;
let mut stream = client.stream()?;
let sender = client.sender();
while let Some(message) = stream.next().await.transpose()? {
match message.command {
Command::PRIVMSG(ref target, ref msg) => {
for i in 0..5 {
sender.send_privmsg(target, i)?;
sleep(Duration::from_secs(1)).await;
}
}
_ => (),
}
}
Ok(())
}
Might be a noob question, I'm learning Rust.
When using
tokio::time::sleepto delay each send_privmsg, it sends them all at once instead of sending one, then delaying, then sending one, etc.Here is a reporducing example, where you can see all message got sent at once after waiting for 5 seconds.