PageRenderTime 12ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

/src/test/run-pass/many.rs

http://github.com/jruderman/rust
Rust | 27 lines | 23 code | 3 blank | 1 comment | 4 complexity | 7f7205ad685ae7eb009f0c83c76bf841 MD5 | raw file
 1// -*- rust -*-
 2
 3use std;
 4import task;
 5import comm;
 6
 7fn sub(parent: comm::chan<int>, id: int) {
 8    if id == 0 {
 9        comm::send(parent, 0);
10    } else {
11        let p = comm::port();
12        let ch = comm::chan(p);
13        let child = task::spawn(|| sub(ch, id - 1) );
14        let y = comm::recv(p);
15        comm::send(parent, y + 1);
16    }
17}
18
19fn main() {
20    let p = comm::port();
21    let ch = comm::chan(p);
22    let child = task::spawn(|| sub(ch, 200) );
23    let y = comm::recv(p);
24    debug!{"transmission complete"};
25    log(debug, y);
26    assert (y == 200);
27}