PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 0ms app.codeStats 0ms

/src/test/run-pass/task-comm-9.rs

http://github.com/jruderman/rust
Rust | 33 lines | 26 code | 7 blank | 0 comment | 3 complexity | 4fc7c4b33a87cd1ee87aeffdc7e18a3e MD5 | raw file
 1use std;
 2import task;
 3
 4fn main() { test00(); }
 5
 6fn test00_start(c: pipes::chan<int>, number_of_messages: int) {
 7    let mut i: int = 0;
 8    while i < number_of_messages { c.send(i + 0); i += 1; }
 9}
10
11fn test00() {
12    let r: int = 0;
13    let mut sum: int = 0;
14    let p = pipes::port_set();
15    let number_of_messages: int = 10;
16    let ch = p.chan();
17
18    let mut result = none;
19    do task::task().future_result(|-r| { result = some(r); }).spawn {
20        test00_start(ch, number_of_messages);
21    }
22
23    let mut i: int = 0;
24    while i < number_of_messages {
25        sum += p.recv();
26        log(debug, r);
27        i += 1;
28    }
29
30    future::get(option::unwrap(result));
31
32    assert (sum == number_of_messages * (number_of_messages - 1) / 2);
33}