#thread-pool #pipe #automatic #constructing #helper #message #communicate

ichika

A helper library for automatically constructing a thread pool that communicates via message pipes

2 releases

0.1.1 Feb 20, 2025
0.1.0 Feb 20, 2025

#5 in #constructing

Download history 267/week @ 2025-02-19 14/week @ 2025-02-26

281 downloads per month

Apache-2.0

14KB
150 lines

ichika

Crates.io License Crates.io Version GitHub Actions Workflow Status

Introduction

This is a helper library for automatically constructing a thread pool that communicates via message pipes. It is based on the flume library that is used to communicate between threads.

The name ichika comes from the character ichika in the game Blue Archive.

Still in development, the API may change in the future.

Quick Start

use ichika::prelude::*;

let pool = pipe! [
  async |(name: String, url: String)| -> anyhow::Result<(String, bytes::Bytes))> {
    Ok((name, id, reqwest::get(url).await?.bytes().await?))
  },
  |(name: String, buffer: bytes::Bytes)| -> anyhow::Result<(String, bytes::Bytes)> {
    let mut decoder = flate2::read::GzDecoder::new();
    let mut ret = vec![];
    decoder.read_to_end(&mut ret)?;
    Ok((name, ret.into()))
  },
  async |(name: String, data: bytes::Bytes)| -> anyhow::Result<()> {
    tokio::fs::write(
      format!("./{name}.dat"),
      &data
    );
    Ok(())
  }
]?;

for i in 0..10 {
  pool.send(("sth", vec![0; 32], "https://example.com".to_string()));
}

for i in 0..10 {
  pool.recv().await?;
}

TODO

  • async, including tokio and async-std.
  • Named task.
  • Limit steps' thread usage.
  • Multiple target match with any depth.
  • Error handle target catch.
  • Retryable target retry with timeout parameter.

Dependencies

~3–14MB
~187K SLoC