Wafer
Wafer copied to clipboard
Push data write to thread
Since we have w_store
persistent, we can send of the file writes to a future or rayon thread.
Potentials is also a candidate obviously, and it's really needed. For large grids these files can take ages to dump.
OK. Think I have a proof of concept for this now.
use std::sync::mpsc::channel;
use std::time::Duration;
use std::thread;
fn calculate_data() -> u32 {
5
}
fn save_data(data: &u32) {
thread::sleep(Duration::from_secs(1));
println!("Saving data: {}", data);
}
fn main() {
let (sender, receiver) = channel();
let save = thread::spawn(move|| {
let data = calculate_data(); //Run calculation
sender.send(data).unwrap(); //Send result to main thread
save_data(&data); //Save data to disk in current thread
});
//data is now available in main thread
println!("{:?}", receiver.recv().unwrap());
save.join().unwrap(); //Blocks until data is written.
println!("done");
}