Skip to content

Throttle results in 100% cpu #583

Closed
@tekjar

Description

@tekjar
use async_std::stream::StreamExt;
use async_std::sync::channel;
use async_std::task;

use std::thread;
use std::time::Duration;

#[async_std::main]
async fn main() {
    let (requests_tx, requests_rx) = channel::<i32>(10);
    let mut requests_rx = requests_rx.throttle(Duration::from_secs(1));

    thread::spawn(move || {
        task::block_on( async {
            for i in 0..5 {
                requests_tx.send(i).await;
            }
        });

        thread::sleep(Duration::from_secs(100));
    });

    while let Some(item) = requests_rx.next().await {
        println!("{:?}", item);
    }
}

Screenshot from 2019-11-24 16-25-27

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions