Skip to content

Sends seem to be buffered #246

@bemug

Description

@bemug

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(())
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions