nautalid 0.1.0

Scratch container substrate — TLS 1.3 HTTP/2+3 kernel, LID/AetherDB, optional filter bus (GPL-3.0-or-later).
//! CPU parallel compute via [rayon], bridged to Tokio.
//!
//! Schedule heavy work with [`spawn_cpu`] so HTTP and I/O stay on the async runtime.
//! Use [`rayon`] (`par_iter`, `join`, etc.) inside the closure when you need parallelism.

pub use rayon;

/// Runs `f` on Tokio's blocking pool (appropriate for CPU-heavy or rayon work).
pub async fn spawn_cpu<F, R>(f: F) -> R
where
    F: FnOnce() -> R + Send + 'static,
    R: Send + 'static,
{
    tokio::task::spawn_blocking(f)
        .await
        .expect("compute worker task panicked")
}

#[cfg(test)]
mod tests {
    use super::spawn_cpu;
    use rayon::prelude::*;

    #[tokio::test]
    async fn spawn_cpu_runs_rayon_parallel_sum() {
        let values: Vec<u64> = (0..10_000).collect();
        let sum = spawn_cpu(move || values.par_iter().copied().sum::<u64>()).await;
        assert_eq!(sum, 10_000 * 9_999 / 2);
    }
}