map_await

Crates.iomap_await
lib.rsmap_await
version0.1.9
sourcesrc
created_at2024-03-30 10:16:50.129354
updated_at2024-06-13 10:35:44.289524
descriptionmap_unordered
homepagehttps://github.com/i18n-site/rust/tree/main/map_unordered
repositoryhttps://github.com/i18n-site/rust.git
max_upload_size
id1190992
size5,816
(3tieto)

documentation

README

map_unordered

use aok::{Result, OK};
use map_await::MapAwait;
use rand::{rngs::OsRng, Rng};
use static_init::constructor;
use tokio_stream::StreamExt;
use tracing::info;

#[constructor(0)]
extern "C" fn init() {
  loginit::init()
}

#[tokio::test]
async fn test() -> Result<()> {
  let mut rng = OsRng;
  let end = rng.gen_range(6..8);
  for range in [0..0, 0..1, 0..4, 0..end] {
    let mut iter = range.clone().map_unordered(3, |i| async move {
      let mut rng = OsRng;
      let sleep = rng.gen_range(1000..2000);
      let i = i + 1;
      info!("{i} begin sleep {}", sleep);
      tokio::time::sleep(std::time::Duration::from_millis(sleep)).await;
      info!("{i} done");
      i
    });
    while let Some(i) = iter.next().await {
      info!("{:?}> {i}", &range);
    }
    info!("------");
  }
  info!("exit");
  OK
}
Commit count: 3

cargo fmt