It's no doubt there's got to be an idiomatic solution to my problem, however
I'm trying to solve it as simple as possible, here the problem in Rust pseudo-code:
let h = std::thread::spawn(|| some_heavy_work());
if some_condition {
let result = h.join().unwrap();
use_result();
std::process::exit(0);
}
let data = some_other_work_in_main();
let result = h.join().unwrap();
use_data_and_result()
As you can see, I'm spawning a task and it runs in parallel, but I might or might not need the result of it earlier. Rust doesn't like two calls to join()
even it's obvious that only one will be called.
How to solve this?