fast-able 1.20.2

The world's martial arts are fast and unbreakable; 天下武功 唯快不破
Documentation
use std::{thread, time::Duration};
use log::info;
use fast_able::fast_thread_pool::TaskExecutor;
use core_affinity::{get_core_ids, CoreId};

fn main() {
    // 初始化日志(使用已有的依赖)
    // env_logger::init(); // 注释掉,因为 env_logger 不在依赖中
    
    let cores = get_core_ids().unwrap();
    let first_core = cores[0];
    
    println!("Testing TaskExecutor with thread_task_bounded feature");
    
    // 测试默认容量的有界 channel(仅在启用 thread_task_bounded feature 时)
    #[cfg(feature = "thread_task_bounded")]
    {
        println!("Creating bounded TaskExecutor with default capacity");
        let executor = TaskExecutor::new(first_core, -1);
        
        // 提交一些任务
        for i in 0..10 {
            executor.spawn(move |core_id| {
                println!("Bounded task {} executed on core {}", i, core_id);
                thread::sleep(Duration::from_millis(100));
            });
        }
        
        // 等待任务完成
        thread::sleep(Duration::from_secs(2));
        println!("Bounded TaskExecutor default test completed");
        
        // 测试自定义容量的有界 channel
        println!("Creating bounded TaskExecutor with custom capacity (5)");
        let custom_executor = TaskExecutor::new_with_capacity(first_core, 5, -1);
        
        for i in 0..8 {
            custom_executor.spawn(move |core_id| {
                println!("Custom bounded task {} executed on core {}", i, core_id);
                thread::sleep(Duration::from_millis(50));
            });
        }
        
        // 测试 try_spawn 方法
        for i in 0..3 {
            let success = custom_executor.try_spawn(move |core_id| {
                println!("Try spawn task {} executed on core {}", i, core_id);
            });
            println!("Try spawn task {}: {}", i, if success { "Success" } else { "Failed (queue full)" });
        }
        
        thread::sleep(Duration::from_secs(2));
        println!("Custom bounded TaskExecutor test completed");
    }
    
    #[cfg(not(feature = "thread_task_bounded"))]
    {
        println!("Creating unbounded TaskExecutor (default behavior)");
        let executor = TaskExecutor::new(first_core, -1);
        
        // 提交一些任务
        for i in 0..10 {
            executor.spawn(move |core_id| {
                println!("Unbounded task {} executed on core {}", i, core_id);
                thread::sleep(Duration::from_millis(100));
            });
        }
        
        // 等待任务完成
        thread::sleep(Duration::from_secs(2));
        println!("Unbounded TaskExecutor test completed");
    }
    
    println!("All tests completed");
}