rust/src/test/run-pass/sendfn-spawn-with-fn-arg.rs

22 lines
367 B
Rust
Raw Normal View History

2011-12-15 18:10:01 -06:00
use std;
2012-09-05 14:32:05 -05:00
use comm::Chan;
use comm::send;
2011-12-15 18:10:01 -06:00
fn main() { test05(); }
fn test05_start(&&f: fn~(int)) {
2011-12-15 18:10:01 -06:00
f(22);
}
fn test05() {
let three = ~3;
let fn_to_send = fn~(n: int) {
log(error, *three + n); // will copy x into the closure
2011-12-15 18:10:01 -06:00
assert(*three == 3);
};
task::spawn(fn~(move fn_to_send) {
2012-01-04 23:14:53 -06:00
test05_start(fn_to_send);
});
2011-12-15 18:10:01 -06:00
}