doc: small tasks guide improvements

This commit is contained in:
Tshepang Lekhonkhobe 2014-08-20 01:34:41 +02:00
parent 51b901e160
commit 17c630a8dd

View File

@ -89,10 +89,9 @@ closure in the new task.
fn print_message() { println!("I am running in a different task!"); } fn print_message() { println!("I am running in a different task!"); }
spawn(print_message); spawn(print_message);
// Print something profound in a different task using a `proc` expression // Alternatively, use a `proc` expression instead of a named function.
// The `proc` expression evaluates to an (unnamed) owned closure. // The `proc` expression evaluates to an (unnamed) owned closure.
// That closure will call `println!(...)` when the spawned task runs. // That closure will call `println!(...)` when the spawned task runs.
spawn(proc() println!("I am also running in a different task!") ); spawn(proc() println!("I am also running in a different task!") );
~~~~ ~~~~
@ -352,14 +351,14 @@ fn main() {
The function `pnorm` performs a simple computation on the vector (it computes the sum of its items The function `pnorm` performs a simple computation on the vector (it computes the sum of its items
at the power given as argument and takes the inverse power of this value). The Arc on the vector is at the power given as argument and takes the inverse power of this value). The Arc on the vector is
created by the line created by the line:
~~~ ~~~
# use std::rand; # use std::rand;
# use std::sync::Arc; # use std::sync::Arc;
# fn main() { # fn main() {
# let numbers = Vec::from_fn(1000000, |_| rand::random::<f64>()); # let numbers = Vec::from_fn(1000000, |_| rand::random::<f64>());
let numbers_arc=Arc::new(numbers); let numbers_arc = Arc::new(numbers);
# } # }
~~~ ~~~