I'm looking for some clarification on task failure. As I understand it, if task 1 spawns task 2, task 2 is a child of task 1. If task 1 fails, does it automatically fail and clean up after task 2?
For example, I start a i/o task on a socket like so:
spawn(proc() {
start_new_socket(socket, socket_receiver)
});
We'll call that task 1. In task 1, I spawn another task:
fn start_new_socket(socket: Socket, receiver: Receiver<Message>) {
// Write task
let mut stream_write = socket.stream.clone();
spawn(proc() {
loop {
let msg = receiver.recv();
msg.send(&mut stream_write).unwrap();
}
});
// Open up a blocking read on this socket
let mut stream_read = socket.stream.clone();
loop {
let msg = Message::load(&mut stream_read).unwrap();
match msg.payload {
Text(ptr) => {
let json_slice = (*ptr).as_slice();
println!("Socket: {} recevied: {}", socket.id, json_slice);
parse_json(json_slice, socket.clone());
}
Binary(ptr) => {
// TODO - Do awesome binary shit
}
}
}
}
If the task 1, start_new_socket
, fails because of EOF
or something else in the stream, does the write task it started also fail?