use std::future::Future;
use std::pin::Pin;
use crate::system::{add_advanced, WorkloadHints};
pub fn add_async(a: Vec<f32>, b: Vec<f32>, hints: WorkloadHints) -> Pin<Box<dyn Future<Output = Vec<f32>> + Send>> {
let _scope = crate::profiler::ProfileScope::new("Async Operation", "CPU", "Async");
Box::pin(async move {
if hints.prefer_gpu {
let gpu_res = crate::gpu::with_backend(|backend: &dyn crate::gpu::GpuBackend| {
backend.add_async(a.clone(), b.clone())
});
if let Some(fut) = gpu_res {
if let Ok(res) = fut.await {
return res;
}
}
}
let (tx, rx) = std::sync::mpsc::channel();
std::thread::spawn(move || {
let mut out = vec![0.0; a.len()];
add_advanced(&a, &b, &mut out, hints);
let _ = tx.send(out);
});
rx.recv().unwrap_or_else(|_| Vec::new())
})
}