Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push data write to thread #13

Open
Libbum opened this issue May 18, 2017 · 3 comments
Open

Push data write to thread #13

Libbum opened this issue May 18, 2017 · 3 comments
Assignees
Labels

Comments

@Libbum
Copy link
Owner

Libbum commented May 18, 2017

Since we have w_store persistent, we can send of the file writes to a future or rayon thread.

@Libbum Libbum added the TODO label May 18, 2017
@Libbum Libbum self-assigned this May 18, 2017
@Libbum
Copy link
Owner Author

Libbum commented May 25, 2017

Potentials is also a candidate obviously, and it's really needed. For large grids these files can take ages to dump.

@Libbum
Copy link
Owner Author

Libbum commented May 29, 2017

@Libbum
Copy link
Owner Author

Libbum commented Aug 9, 2017

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");
}

@Libbum Libbum added this to the Initial release milestone Aug 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant