News for hackers. Stuff that matters.
Re:This Week in Rust – Static linking, Win64 by portmanteaufu on Sunday December 01, 2013 @08:33PM (#6830628)
I read about this in the mailing list, but never having relied on linked failure in the past I wasn't sure what the implications were. Could someone give an example of when this would've been used before and how you might accomplish the same in its absence?
Re:This Week in Rust – Static linking, Win64 by eridius on Sunday December 01, 2013 @09:27PM (#6831027)
With linked task failure, this program here would cause the main task to fail, which results in the entire program aborting (once all tasks have finished failing):

    fn main() {
        // we can't introduce synchronization for this example, so print repeatedly on the main task and check the output for ordering
        do spawn {
            fail!("child task failure");
        }
        for i in range(0u, 50) {
            println!("print line {}", i);
        }
    }
Without linked task failure, the spawned task will fail, but the main task will continue on.

If you want to reintroduce linked task failure with current master, you can do so explicitly using `std::task::TaskBuilder.future_result()`. It's a bit awkward though. And you can probably do better than what I have here, it's just a quick sample:

    fn main() {
        let mut builder = std::task::task();
        let future = builder.future_result();
        do builder.spawn() {
            fail!("child task failure");
        }
        // check for failure before each of our prints
        for i in range(0u, 50) {
            if future.peek() && future.recv().is_err() {
                fail!("parent task failing because of child failure");
            }
            println!("print line {}", i);
        }
        // and block on the result in the end
        if future.try_recv().map_default(false, |r| r.is_err()) {
            fail!("parent task failing because of child failure");
        }
    }