< 返回版块

lispking 发表于 2025-06-03 21:25

Tags:Rust,tokio,thread-pool

tokio-fusion 是一个基于 Tokio 构建的高性能线程池服务仓库,提供了简单易用的异步任务执行 API。

仓库地址:https://github.com/lispking/tokio-fusion

项目概述

  • 核心功能:提供了一个线程池服务,用于异步任务的高效执行。它支持单个任务和批量任务的提交,同时支持任务优先级设置、流式结果返回、可配置的工作线程和队列容量,以及完善的错误处理。
  • 性能优势:基于 Tokio 的高效运行时,利用工作窃取算法优化任务调度,提高整体性能。

使用案例

use std::sync::Arc;
use tokio_fusion::{ThreadPool, Task, ThreadPoolResult};

async fn my_task(id: usize) -> ThreadPoolResult<String> {
    // Your async task logic here
    Ok(format!("Result from task {id}"))
}

#[tokio::main]
async fn main() {
    // Create a thread pool with default configuration
    let thread_pool = Arc::new(ThreadPool::default());
    
    // Create and submit a task
    let task = Task::new(my_task(1), 1);
    let handle = thread_pool.submit(task).await.unwrap();
    
    // Wait for the result
    let result = handle.await_result().await;
    println!("Task result: {:?}", result);
}

评论区

写评论

还没有评论

1 共 0 条评论, 1 页