11 releases

new 0.1.11 Feb 6, 2025
0.1.10 Aug 17, 2024
0.1.9 Jun 13, 2024
0.1.8 Mar 31, 2024

#106 in #await

Download history 2/week @ 2024-10-11 12/week @ 2024-12-06 3/week @ 2024-12-27

545 downloads per month
Used in s3_put

MulanPSL-2.0

12KB
94 lines

map_unordered

use aok::{Result, OK};
use map_await::MapAwait;
use rand::{rngs::StdRng, Rng, SeedableRng};
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 = StdRng::from_rng(&mut rand::rng());
  let end = rng.random_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 = StdRng::from_rng(&mut rand::rng());
      let sleep = rng.random_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
}

About

This project is an open-source component of i18n.site ⋅ Internationalization Solution.

关于

本项目为 i18n.site ⋅ 国际化解决方案 的开源组件。

Dependencies

~2.7–9.5MB
~72K SLoC