-
#[tokio::main]
async fn main() {
let (tx, rx) = flume::bounded::<i32>(1_000_000);
let task1 = async move {
let rate_limiter = governor::RateLimiter::direct(governor::Quota::per_second(
std::num::NonZeroU32::new(10_000_000).unwrap(),
));
let jitter = governor::Jitter::up_to(std::time::Duration::from_millis(10));
let mut n = 0;
loop {
n += 1;
// tokio::task::yield_now().await;
rate_limiter.until_ready_with_jitter(jitter).await;
tx.send(n).unwrap();
}
};
let task2 = async move {
println!("task2 started"); // <- does not run
while let Ok(item) = rx.recv_async().await {
println!("received {}", item);
}
};
futures::future::join(task1, task2).await;
} task1 generates messages and task2 receives. I guess |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Found the answer in the doc of tokio::join: "concurrently but not in parallel" |
Beta Was this translation helpful? Give feedback.
Found the answer in the doc of tokio::join: "concurrently but not in parallel"