#thread-pool #thread #pool #async-task #parallel #async

threadfin

在可配置的线程组上运行多个任务的线程池

3 个版本

0.1.2 2023年2月6日
0.1.1 2021年12月6日
0.1.0 2021年11月3日

#549并发

Download history 3/week @ 2024-03-14 5/week @ 2024-03-21 30/week @ 2024-03-28 24/week @ 2024-04-04 11/week @ 2024-04-11 6/week @ 2024-04-25

每月 177 次下载

MIT 许可证

59KB
886

Threadfin

在可配置的线程组上运行多个任务的线程池。

Crates.io Documentation License Minimum supported Rust version Build

额外功能

  • 基于负载的动态池大小
  • 支持异步任务
  • 任务返回一个句柄,可以用于连接或等待返回值
  • 可选的通用进程级线程池

异步支持

Threadfin 通过 futures 支持异步使用,并允许您在单个线程池中混合使用同步和异步任务。

示例

// Create a new pool.
let pool = threadfin::builder().size(8).build();

// Schedule some work.
let compute_task = pool.execute(|| {
    // Some expensive computation
    2 + 2
});

// Do something in the meantime.
println!("Waiting for result...");

// Wait for the task to complete and get the result.
let sum = compute_task.join();
println!("Sum: 2 + 2 = {}", sum);

安装

通过在 Cargo.toml 文件中添加来安装

[dependencies]
threadfin = "0.1"

最小支持的 Rust 版本

Threadfin 的最小支持 Rust 版本(或 MSRV)是稳定版 Rust 1.46 或更高版本,这意味着我们只能保证如果使用至少 1.46 的 rustc 版本,Threadfin 将会编译。它可能可以使用旧版本编译,但这可能在任何时候改变。

此版本已在 CI 中明确测试,并且可能仅在新的次要版本中提升。对支持的最低版本所做的任何更改都将记录在发行说明中。

其他库

赞助商

特别感谢赞助我的开源工作的人!

da-moon

许可证

根据 MIT 许可证授权。有关详细信息,请参阅 LICENSE 文件。

依赖关系

~520KB