pub fn foo<T:Send + Clone>(x: T) -> Port<T> {
let (p, c) = Chan::new();
- do task::spawn() {
+ task::spawn(proc() {
c.send(x.clone());
- }
+ });
p
}
let to_child = to_child.clone();
let mut builder = task::task();
worker_results.push(builder.future_result());
- do builder.spawn {
+ builder.spawn(proc() {
for _ in range(0u, size / workers) {
//error!("worker {:?}: sending {:?} bytes", i, num_bytes);
to_child.send(bytes(num_bytes));
}
//error!("worker {:?} exiting", i);
- }
+ });
}
- do task::spawn || {
+ task::spawn(proc() {
server(&from_parent, &to_parent);
- }
+ });
for r in worker_results.iter() {
r.recv();
let (from_parent, to_child) = Chan::new();
let mut builder = task::task();
worker_results.push(builder.future_result());
- do builder.spawn {
+ builder.spawn(proc() {
for _ in range(0u, size / workers) {
//error!("worker {:?}: sending {:?} bytes", i, num_bytes);
to_child.send(bytes(num_bytes));
}
//error!("worker {:?} exiting", i);
- };
+ });
from_parent
} else {
let (from_parent, to_child) = SharedChan::new();
let to_child = to_child.clone();
let mut builder = task::task();
worker_results.push(builder.future_result());
- do builder.spawn {
+ builder.spawn(proc() {
for _ in range(0u, size / workers) {
//error!("worker {:?}: sending {:?} bytes", i, num_bytes);
to_child.send(bytes(num_bytes));
}
//error!("worker {:?} exiting", i);
- };
+ });
}
from_parent
};
- do task::spawn || {
+ task::spawn(proc() {
server(&from_parent, &to_parent);
- }
+ });
for r in worker_results.iter() {
r.recv();
//error!("spawning %?", i);
let (new_chan, num_port) = init();
let num_chan_2 = num_chan.clone();
- let new_future = do Future::spawn() {
+ let new_future = Future::spawn(proc() {
thread_ring(i, msg_per_task, num_chan_2, num_port)
- };
+ });
futures.push(new_future);
num_chan = new_chan;
};
//error!("spawning %?", i);
let (new_chan, num_port) = init();
let num_chan_2 = num_chan.clone();
- let new_future = do Future::spawn {
+ let new_future = Future::spawn(proc() {
thread_ring(i, msg_per_task, num_chan_2, num_port)
- };
+ });
futures.push(new_future);
num_chan = new_chan;
};
// Create a stream B->A
let (pb,cb) = Chan::<()>::new();
- do spawn() || {
+ spawn(proc() {
let chan = ca;
let port = pb;
n.times(|| {
chan.send(());
port.recv();
})
- }
+ });
- do spawn() || {
+ spawn(proc() {
let chan = cb;
let port = pa;
n.times(|| {
port.recv();
chan.send(());
})
- }
+ });
}
m.times(|| {
}
let (port,chan) = Chan::new();
- do spawn {
+ spawn(proc() {
chan.send(parfib(n-1));
- };
+ });
let m2 = parfib(n-2);
return (port.recv() + m2);
}
};
n.times(|| {
- do spawn || {};
+ spawn(proc() {});
})
}
let mut messages = range_step(min_depth, max_depth + 1, 2).map(|depth| {
use std::num::pow;
let iterations = pow(2, (max_depth - depth + min_depth) as uint);
- do Future::spawn {
+ Future::spawn(proc() {
let mut chk = 0;
for i in range(1, iterations + 1) {
let arena = TypedArena::new();
}
format!("{}\t trees of depth {}\t check: {}",
iterations * 2, depth, chk)
- }
+ })
}).to_owned_vec();
for message in messages.mut_iter() {
let to_rendezvous = to_rendezvous.clone();
let to_rendezvous_log = to_rendezvous_log.clone();
let (from_rendezvous, to_creature) = Chan::new();
- do task::spawn {
+ task::spawn(proc() {
creature(ii,
col,
from_rendezvous,
to_rendezvous.clone(),
to_rendezvous_log.clone());
- }
+ });
to_creature
}).collect();
let (from_parent, to_child) = Chan::new();
- do spawn {
+ spawn(proc() {
make_sequence_processor(sz, &from_parent, &to_parent_);
- }
+ });
to_child
}).collect::<~[Chan<~[u8]>]>();
for i in range(0, num_tasks) {
let mut builder = task::task();
results.push(builder.future_result());
- do builder.spawn {
+ builder.spawn(proc() {
stress_task(i);
- }
+ });
}
for r in results.iter() {
r.recv();
let w = wait.clone();
let v = v.clone();
let out = out.clone();
- do spawn {
+ spawn(proc() {
for i in range(chk, min(len, chk + chunk)) {
let val = v.read(|v| f(v, i));
out.write(|out| out[i] = val);
}
let _ = w;
- }
+ });
}
let _ = wait.unwrap();
}
let (next_p, ch) = Chan::new();
let imm_i = i;
let imm_p = p;
- do spawn {
+ spawn(proc() {
roundtrip(imm_i, n_tasks, &imm_p, &ch);
- };
+ });
p = next_p;
i += 1;
}
let imm_p = p;
let imm_ch = ch1;
- do spawn {
+ spawn(proc() {
roundtrip(1, n_tasks, &imm_p, &imm_ch);
- }
+ });
}
fn roundtrip(id: int, n_tasks: int, p: &Port<int>, ch: &Chan<int>) {
// Useful smoketest for scheduler performance.
fn main() {
for _ in range(1, 100_000) {
- do spawn { }
+ spawn(proc() {})
}
}
// Useful for checking syscall usage of baseline scheduler usage
fn main() {
- do spawn { }
+ spawn(proc() {});
}
fn run(repeat: int, depth: int) {
for _ in range(0, repeat) {
info!("starting {:.4f}", precise_time_s());
- do task::try {
+ task::try(proc() {
recurse_or_fail(depth, None)
- };
+ });
info!("stopping {:.4f}", precise_time_s());
}
}
// This used to be O(n^2) in the number of generations that ever existed.
// With this code, only as many generations are alive at a time as tasks
// alive at a time,
- do spawn {
+ spawn(proc() {
if gens_left & 1 == 1 {
task::deschedule(); // shake things up a bit
}
} else {
c.send(())
}
- }
+ });
}
fn main() {
for _ in range(0, num_tasks) {
let ch = ch.clone();
let mut t = task::task();
- do t.spawn { // linked
+ t.spawn(proc() { // linked
ch.send(());
let (p, _c) = stream::<()>();
p.recv(); // block forever
- }
+ });
}
error!("Grandchild group getting started");
for _ in range(0, num_tasks) {
// Main group #0 waits for unsupervised group #1.
// Grandparent group #1 waits for middle group #2, then fails, killing #3.
// Middle group #2 creates grandchild_group #3, waits for it to be ready, exits.
- let x: result::Result<(), ~Any> = do task::try { // unlinked
- do spawn_supervised_blocking("grandparent") {
- do spawn_supervised_blocking("middle") {
+ let x: result::Result<(), ~Any> = task::try(proc() { // unlinked
+ spawn_supervised_blocking("grandparent", proc() {
+ spawn_supervised_blocking("middle", proc() {
grandchild_group(num_tasks);
- }
+ });
// When grandchild group is ready to go, make the middle group exit.
error!("Middle group wakes up and exits");
- }
+ });
// Grandparent group waits for middle group to be gone, then fails
error!("Grandparent group wakes up and fails");
fail!();
- };
+ });
assert!(x.is_err());
}
let wait_ports: ~[Port<Chan<Chan<int>>>] = vec::from_fn(children, |_| {
let (wait_port, wait_chan) = stream::<Chan<Chan<int>>>();
- do task::spawn {
+ task::spawn(proc() {
calc(children / 2, &wait_chan);
- }
+ });
wait_port
});
let children = from_str::<uint>(args[1]).unwrap();
let (wait_port, wait_chan) = stream();
- do task::spawn {
+ task::spawn(proc() {
calc(children, &wait_chan);
- };
+ });
let start_chan = wait_port.recv();
let (sum_port, sum_chan) = stream::<int>();
});
y.unwrap();
// Adding this line causes a method unification failure instead
- // do (&option::unwrap(y)).read |state| { assert!(*state == 1); }
+ // (&option::unwrap(y)).read(|state| { assert!(*state == 1); })
}
x.write_downgrade(|write_mode| y = Some(write_mode));
y.unwrap();
// Adding this line causes a method unification failure instead
- // do (&option::unwrap(y)).write |state| { assert!(*state == 1); }
+ // (&option::unwrap(y)).write(|state| { assert!(*state == 1); })
}
fn box_imm() {
let v = ~3;
let _w = &v;
- do task::spawn {
+ task::spawn(proc() {
info!("v={}", *v);
//~^ ERROR cannot move `v` into closure
- }
+ });
let v = ~3;
let _w = &v;
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-fn main() {
- do something
- |x| do somethingelse //~ ERROR: expected `{` but found `do`
- |y| say(x, y)
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-fn main() {
- let x = do y; //~ ERROR: expected `{` but found
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-fn f(f: proc(int) -> bool) -> bool { f(10i) }
-
-fn main() {
- assert!(do f() |i| { i == 10i } == 10i);
- //~^ ERROR: expected `bool` but found `int`
-}
fn main() {
let needlesArr: ~[char] = ~['a', 'f'];
- do needlesArr.iter().fold() |x, y| {
- }
- //~^^ ERROR 1 parameter was supplied (including the closure passed by the `do` keyword)
+ needlesArr.iter().fold(|x, y| {
+ });
+ //~^^ ERROR this function takes 2 parameters but 1 parameter was supplied
//
// the first error is, um, non-ideal.
}
+++ /dev/null
-// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// This file was auto-generated using 'src/etc/generate-keyword-tests.py do'
-
-fn main() {
- let do = "foo"; //~ error: ident
-}
fn main() {
let x = ~"Hello world!";
- do task::spawn {
+ task::spawn(proc() {
println!("{}", x);
- }
+ });
println!("{}", x); //~ ERROR use of moved value
}
let arc = ~MutexArc::new(1);
let arc2 = ~MutexArc::new(*arc);
- do task::spawn || {
+ task::spawn(proc() {
(*arc2).access(|mutex| { //~ ERROR instantiating a type parameter with an incompatible type
})
- };
+ });
}
fn main() {}
let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let arc_v = arc::Arc::new(v);
- do task::spawn() {
+ task::spawn(proc() {
let v = arc_v.get();
assert_eq!(v[3], 4);
- };
+ });
assert_eq!((arc_v.get())[2], 3);
let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let arc_v = arc::Arc::new(v);
- do task::spawn() {
+ task::spawn(proc() {
let v = arc_v.get();
assert_eq!(v[3], 4);
- };
+ });
assert_eq!((arc_v.get())[2], 3); //~ ERROR use of moved value: `arc_v`
let x = foo(Port(@()));
- do task::spawn {
+ task::spawn(proc() {
let y = x; //~ ERROR does not fulfill `Send`
error!("{:?}", y);
- }
+ });
}
fn main() {
let x = arc::Arc::new(true);
- do foo {
+ foo(proc() {
assert!(*x.get());
drop(x);
- }
+ });
}
y = Some(x.downgrade(write_mode));
})
// Adding this line causes a method unification failure instead
- // do (&option::unwrap(y)).read { }
+ // (&option::unwrap(y)).read(proc() { });
}
y = Some(write_mode);
});
// Adding this line causes a method unification failure instead
- // do (&option::unwrap(y)).write { }
+ // (&option::unwrap(y)).write(proc() { })
}
}
fn main() {
- do 10u.times {
- do task::spawn {
+ 10u.times(proc() {
+ task::spawn(proc() {
let result = count(5u);
info!("result = %?", result);
fail!();
- };
- }
+ });
+ });
}
use std::task;
fn main() {
- do task::try {
+ task::try(proc() {
fail!("test");
1
- }.unwrap()
+ }).unwrap()
}
fn main() {
let mut t = task::task();
t.name(~"owned name");
- do t.try {
+ t.try(proc() {
fail!("test");
1
- }.unwrap()
+ }).unwrap()
}
fn main() {
let mut t = ::std::task::task();
t.name("send name".to_send_str());
- do t.try {
+ t.try(proc() {
fail!("test");
3
- }.unwrap()
+ }).unwrap()
}
fn main() {
let mut t = ::std::task::task();
t.name("static name");
- do t.try {
+ t.try(proc() {
fail!("test");
- }.unwrap()
+ }).unwrap()
}
}
fn main() {
- do task::spawn {
+ task::spawn(proc() {
let r = and_then_get_big_again(4);
getbig_call_c_and_fail(10000);
- };
+ });
}
}
fn main() {
- do task::spawn {
+ task::spawn(proc() {
getbig_and_fail(400);
- };
+ });
}
}
fn main() {
- do task::spawn {
+ task::spawn(proc() {
getbig_and_fail(1);
- };
+ });
}
#[start]
fn start(argc: int, argv: **u8) -> int {
- do native::start(argc, argv) {
+ native::start(argc, argv, proc() {
fail!();
- }
+ })
}
fn main() {
error!("whatever");
- do task::spawn {
+ task::spawn(proc() {
let _i = r(5);
- };
+ });
fail!();
}
#[no_mangle] // this needs to get called from C
pub extern "C" fn foo(argc: int, argv: **u8) -> int {
- do green::start(argc, argv) {
- do spawn {
+ green::start(argc, argv, proc() {
+ spawn(proc() {
println!("hello");
- }
- }
+ });
+ })
}
#[no_mangle] // this needs to get called from C
pub extern "C" fn foo(argc: int, argv: **u8) -> int {
- do native::start(argc, argv) {
- do spawn {
+ native::start(argc, argv, proc() {
+ spawn(proc() {
println!("hello");
- }
- }
+ });
+ })
}
}
fn main() {
- do task::try {
+ task::try(proc() {
let _a = A;
lib::callback(|| fail!());
1
- };
+ });
unsafe {
assert!(lib::statik == 1);
fn check_pp<T>(cx: fake_ext_ctxt,
expr: T, f: |pprust::ps, T|, expect: ~str) {
- let s = do io::with_str_writer |wr| {
+ let s = io::with_str_writer(|wr| {
let pp = pprust::rust_printer(wr, cx.parse_sess().interner);
f(pp, expr);
pp::eof(pp.s);
- };
+ });
stdout().write_line(s);
if expect != ~"" {
error!("expect: '%s', got: '%s'", expect, s);
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-fn add(x: proc(f64) -> f64) -> f64 {
- x(10.0)
-}
-
-pub fn main() {
- // Trailing expressions don't require parentheses:
- let y = do add |x| { x + 10.0 } + 10.0;
-
- assert_eq!(y, 30.0);
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-fn f(_: proc()) -> proc(proc() -> uint) {
- proc(_: proc() -> uint) {}
-}
-
-pub fn main() {
- do do f {} { 20 };
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-fn f(_: proc()) -> proc(uint) -> uint {
- proc(x: uint) { x }
-}
-
-pub fn main() {
- let z = do f {} (22u);
- assert_eq!(z, 22u);
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-fn f(_: proc(int, int) -> int) -> int {
- 10
-}
-
-fn w_semi() {
- // the semicolon causes compiler not to
- // complain about the ignored return value:
- do f |x, y| { x+y };
-}
-
-fn w_paren1() -> int {
- (do f |x, y| { x+y }) - 10
-}
-
-fn w_paren2() -> int {
- (do f |x, y| { x+y } - 10)
-}
-
-fn w_ret() -> int {
- return do f |x, y| { x+y } - 10;
-}
-
-pub fn main() {
- w_semi();
- w_paren1();
- w_paren2();
- w_ret();
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-fn call_any(f: proc() -> uint) -> uint {
- return f();
-}
-
-pub fn main() {
- let x_r = do call_any { 22u };
- assert_eq!(x_r, 22u);
-}
info!("{:?}", *i);
}
- // Usable at all:
- do inty |x| { x };
-
- // Higher precedence than assignments:
- let result = do inty |e| { e };
- assert_eq!(result, 100);
-
- // Higher precedence than unary operations:
- let stringy = do inty |e| { e }.to_str();
- assert!(do booly |_| { true });
- assert!(!do booly |_| { false });
-
- // Usable in funny statement-like forms:
- if !do booly |_| { true } {
- assert!(false);
- }
- match do booly |_| { false } {
- true => { fail!("incorrect answer."); }
- false => { }
- }
- match 3 {
- _ if do booly |_| { true } => {
- }
- _ => {
- fail!("wrong answer.");
- }
- }
-
-
- // Lower precedence than binary operations:
- let w = do inty |_| { 10 } + 10;
- let y = do inty |_| { 10 } + 10;
- let z = 10 + do inty |_| { 10 };
- assert_eq!(w, y);
- assert_eq!(y, z);
-
- // In the tail of a block
- let w = if true {
- do booly |_| {
- true
- }
- } else {
- false
- };
- assert!(w);
}
fn foo(x: ()) -> Port<()> {
let (p, c) = Chan::<()>::new();
- do task::spawn() {
+ task::spawn(proc() {
c.send(x);
- }
+ });
p
}
#[start]
fn start(argc: int, argv: **u8) -> int {
- do native::start(argc, argv) {
+ native::start(argc, argv, proc() {
main();
- }
+ })
}
fn main() {
let (p, c) = Chan::new();
let (mut r, w) = (PortReader::new(p), ChanWriter::new(c));
- do spawn {
+ spawn(proc() {
set_logger(~MyWriter(w) as ~Logger);
debug!("debug");
info!("info");
- }
+ });
assert_eq!(r.read_to_str(), ~"info\n");
}
pub fn main() {
let (p,c) = Chan::new();
- do foo {
+ foo(proc() {
c.send(());
- }
+ });
p.recv();
}
pub fn main() {
// Procs
- let greeting = ~"Hi ";
- do call_it |s| {
- greeting + s
- }
-
let greeting = ~"Hello ";
call_it(proc(s) {
greeting + s
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// no-reformat
-// Testing various forms of `do` with empty arg lists
-
-fn f(_f: proc() -> bool) -> bool {
- true
-}
-
-pub fn main() {
- do f() || { true };
- do f() { true };
- do f || { true };
- do f { true };
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// Testing that we can drop the || in do exprs
-
-fn f(_f: proc() -> bool) -> bool { true }
-
-fn d(_f: proc()) { }
-
-pub fn main() {
- do d { }
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-fn f(f: proc(int)) { f(10) }
-
-pub fn main() {
- do f() |i| { assert!(i == 10) }
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-fn f(f: proc(int) -> int) -> int { f(10) }
-
-pub fn main() {
- assert_eq!(do f() |i| { i }, 10);
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-fn f(f: proc(int) -> int) -> int { f(10) }
-
-pub fn main() {
- assert_eq!(do f |i| { i }, 10);
-}
pub fn main() {
// Make sure we're on a task with small Rust stacks (main currently
// has a large stack)
- do task::spawn {
+ task::spawn(proc() {
let result = count(1000u);
info!("result = {}", result);
assert_eq!(result, 1000u);
- };
+ });
}
pub fn main() {
// Make sure we're on a task with small Rust stacks (main currently
// has a large stack)
- do task::spawn {
+ task::spawn(proc() {
let result = count(12u);
info!("result = {}", result);
assert_eq!(result, 2048u);
- };
+ });
}
pub fn main() {
100u.times(|| {
- do task::spawn {
+ task::spawn(proc() {
assert_eq!(count(5u), 16u);
- };
+ });
})
}
pub fn main() {
10u.times(|| {
- do task::spawn {
+ task::spawn(proc() {
let result = count(5u);
info!("result = {}", result);
assert_eq!(result, 16u);
- };
+ });
})
}
}
pub fn main() {
- let ret = do task::try {
+ let ret = task::try(proc() {
let _a = A { b: B { foo: 3 } };
- };
+ });
assert!(ret.is_err());
unsafe { assert!(dropped); }
}
pub fn main() {
unsafe {
- do run_in_bare_thread() {
+ run_in_bare_thread(proc() {
let i = &100;
rust_dbg_call(callback, cast::transmute(i));
- }
+ });
}
}
extern mod extra;
fn loopy(n: int) {
- if n > 0 { do spawn { loopy(n - 1) }; do spawn { loopy(n - 1) }; }
+ if n > 0 { spawn(proc() { loopy(n - 1) }); spawn(proc() { loopy(n - 1) }); }
loop { }
}
// Commenting this out, as this will hang forever otherwise.
// Even after seeing the comment above, I'm not sure what the
// intention of this test is.
- // do spawn { loopy(5) };
+ // spawn(proc() { loopy(5) });
}
}
fn filter<A,IA:iterable<A>>(self: IA, prd: 'static |A| -> bool, blk: |A|) {
- do self.iter |a| {
+ self.iter(|a| {
if prd(a) { blk(a) }
- }
+ });
}
fn foldl<A,B,IA:iterable<A>>(self: IA, b0: B, blk: |B, A| -> B) -> B {
let mut b = b0;
- do self.iter |a| {
+ self.iter(|a| {
b = blk(b, a);
- }
+ });
b
}
pub fn main() {
let (p,c) = comm::stream();
- do task::try || {
+ task::try(|| {
let (p2,c2) = comm::stream();
- do task::spawn || {
+ task::spawn(|| {
p2.recv();
error!("sibling fails");
fail!();
- }
+ });
let (p3,c3) = comm::stream();
c.send(c3);
c2.send(());
error!("child blocks");
p3.recv();
- };
+ });
error!("parent tries");
assert!(!p.recv().try_send(()));
error!("all done!");
}
fn foo(name: ~str, samples_chan: Chan<Msg>) {
- do task::spawn
- {
+ task::spawn(proc() {
let mut samples_chan = samples_chan;
let callback: SamplesFn = proc(buffer) {
for i in range(0u, buffer.len()) {
}
};
samples_chan.send(GetSamples(name.clone(), callback));
- };
+ });
}
pub fn main() {}
priv fn parse_list(len: uint, io: @io::Reader) -> Result {
let mut list: ~[Result] = ~[];
- do len.times {
+ len.times(proc() {
let v =
match io.read_char() {
'$' => parse_bulk(io),
':' => parse_int(io),
_ => fail!()
- };
+ });
list.push(v);
}
return List(list);
fn query2(cmd: ~[~str]) -> Result {
let _cmd = cmd_to_str(cmd);
- do io::with_str_reader(~"$3\r\nXXX\r\n") |sb| {
+ io::with_str_reader(~"$3\r\nXXX\r\n")(|sb| {
let res = parse_response(@sb as @io::Reader);
println!("{:?}", res);
res
- }
+ });
}
pub fn main() {
let (port, chan) = Chan::new();
- do spawn {
+ spawn(proc() {
println(port.recv());
- }
+ });
chan.send("hello, world");
}
pub fn main() {
let (port, chan) = Chan::<&'static str>::new();
- do task::spawn {
+ task::spawn(proc() {
assert_eq!(port.recv(), "hello, world");
- }
+ });
chan.send("hello, world");
}
// Here, i is *copied* into the proc (heap closure).
// Requires allocation. The proc's copy is not mutable.
let mut i = 0;
- do task::spawn {
+ task::spawn(proc() {
user(i);
println!("spawned {}", i)
- }
+ });
i += 1;
println!("original {}", i)
}
// mutable outside of the proc.
let mut i = 0;
while i < 10 {
- do task::spawn {
+ task::spawn(proc() {
user(i);
- }
+ });
i += 1;
}
}
// Here, i must be shadowed in the proc to be mutable.
let mut i = 0;
while i < 10 {
- do task::spawn {
+ task::spawn(proc() {
let mut i = i;
i += 1;
user(i);
- }
+ });
i += 1;
}
}
pub fn main() {
let (p,c) = Chan::new();
- do spawn {
+ spawn(proc() {
let mut f = Foo(Cell::new(0));
debug!("{}", f);
let Foo(ref mut f) = f;
assert!(f.get() == 1);
c.send(());
- }
+ });
p.recv();
}
pub fn main() {
let x = ~"Hello world!";
- do task::spawn {
+ task::spawn(proc() {
println!("{}", x);
- }
+ });
}
#[start]
fn start(argc: int, argv: **u8) -> int {
// make sure that native::start always waits for all children to finish
- do native::start(argc, argv) {
- do spawn {
+ native::start(argc, argv, proc() {
+ spawn(proc() {
unsafe { set = true; }
- }
- };
+ });
+ });
// if we didn't set the global, then return a nonzero code
if unsafe {set} {0} else {1}
}
fn main() {
- do task::try::<()> {
+ task::try::<()>(proc() {
let _a = A;
fail!();
- };
+ });
assert!(unsafe { !HIT });
}
pub fn main() {
let x = arc::Arc::new(true);
- do foo {
+ foo(proc() {
assert!(*x.get());
drop(x);
- }
+ });
}
let (port, chan) = stream();
info!("main started");
- do spawn {
+ spawn(proc() {
starve_main(port);
- };
+ });
let mut i: int = 0;
info!("main waiting for alive signal");
chan.send(i);
pub fn main() {
let (p, c) = Chan::new();
- do task::spawn() {
+ task::spawn(proc() {
let (pp, cc) = Chan::new();
c.send(cc);
let _r = pp.recv();
- }
+ });
p.recv().send(test(42));
}
let i: int = 0;
let mut builder = task::task();
let mut result = builder.future_result();
- do builder.spawn {
+ builder.spawn(proc() {
start(i)
- }
+ });
// Sleep long enough for the task to finish.
let mut i = 0;
let number_of_messages: int = 10;
let c = ch.clone();
- do task::spawn || {
+ task::spawn(proc() {
test00_start(&c, number_of_messages * 0, number_of_messages);
- }
+ });
let c = ch.clone();
- do task::spawn || {
+ task::spawn(proc() {
test00_start(&c, number_of_messages * 1, number_of_messages);
- }
+ });
let c = ch.clone();
- do task::spawn || {
+ task::spawn(proc() {
test00_start(&c, number_of_messages * 2, number_of_messages);
- }
+ });
let c = ch.clone();
- do task::spawn || {
+ task::spawn(proc() {
test00_start(&c, number_of_messages * 3, number_of_messages);
- }
+ });
let mut i: int = 0;
while i < number_of_messages {
let mut builder = task::task();
let result = builder.future_result();
- do builder.spawn {
+ builder.spawn(proc() {
let mut ch = ch;
test00_start(&mut ch, number_of_messages);
- }
+ });
let mut i: int = 0;
while i < number_of_messages {
*b = true;
}
let (p, c) = stream();
- do task::spawn_unlinked {
+ task::spawn_unlinked(proc() {
let ccc = c;
wrapper(ccc, f)
- }
+ });
p
}
~dogge2 as ~Pet:Freeze+Send]);
let (p1,c1) = Chan::new();
let arc1 = arc.clone();
- do task::spawn { check_legs(arc1); c1.send(()); }
+ task::spawn(proc() { check_legs(arc1); c1.send(()); });
let (p2,c2) = Chan::new();
let arc2 = arc.clone();
- do task::spawn { check_names(arc2); c2.send(()); }
+ task::spawn(proc() { check_names(arc2); c2.send(()); });
let (p3,c3) = Chan::new();
let arc3 = arc.clone();
- do task::spawn { check_pedigree(arc3); c3.send(()); }
+ task::spawn(proc() { check_pedigree(arc3); c3.send(()); });
p1.recv();
p2.recv();
p3.recv();
}
pub fn main() {
- let x = do task::try {
+ let x = task::try(proc() {
let _b = Foo;
- };
+ });
let s = x.unwrap_err().move::<&'static str>().unwrap();
assert_eq!(s.as_slice(), "This failure should happen.");