Skip to content

Tweak copy and formatting of Tasks guide #17955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/doc/guide-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ concurrency: particularly, ownership. The language leaves the implementation
details to the standard library.

The `spawn` function has a very simple type signature: `fn spawn(f: proc():
Send)`. Because it accepts only procs, and procs contain only owned data,
Send)`. Because it accepts only procs, and procs contain only owned data,
`spawn` can safely move the entire proc and all its associated state into an
entirely different task for execution. Like any closure, the function passed to
`spawn` may capture an environment that it carries across tasks.
Expand Down Expand Up @@ -213,7 +213,7 @@ println!("fib(50) = {}", delayed_fib.get())
# }
```

The call to `future::spawn` returns immediately a `future` object regardless of
The call to `future::spawn` immediately returns a `future` object regardless of
how long it takes to run `fib(50)`. You can then make yourself a sandwich while
the computation of `fib` is running. The result of the execution of the method
is obtained by calling `get` on the future. This call will block until the
Expand Down Expand Up @@ -297,7 +297,7 @@ let numbers_arc = Arc::new(numbers);
```

and a clone is captured for each task via a procedure. This only copies
the wrapper and not it's contents. Within the task's procedure, the captured
the wrapper and not its contents. Within the task's procedure, the captured
Arc reference can be used as a shared reference to the underlying vector as
if it were local.

Expand All @@ -323,20 +323,20 @@ Rust has a built-in mechanism for raising exceptions. The `fail!()` macro
(which can also be written with an error string as an argument: `fail!(
~reason)`) and the `assert!` construct (which effectively calls `fail!()` if a
boolean expression is false) are both ways to raise exceptions. When a task
raises an exception the task unwinds its stack---running destructors and
freeing memory along the way---and then exits. Unlike exceptions in C++,
raises an exception, the task unwinds its stackrunning destructors and
freeing memory along the wayand then exits. Unlike exceptions in C++,
exceptions in Rust are unrecoverable within a single task: once a task fails,
there is no way to "catch" the exception.

While it isn't possible for a task to recover from failure, tasks may notify
each other of failure. The simplest way of handling task failure is with the
`try` function, which is similar to `spawn`, but immediately blocks waiting for
the child task to finish. `try` returns a value of type `Result<T, Box<Any +
Send>>`. `Result` is an `enum` type with two variants: `Ok` and `Err`. In this
case, because the type arguments to `Result` are `int` and `()`, callers can
pattern-match on a result to check whether it's an `Ok` result with an `int`
field (representing a successful result) or an `Err` result (representing
termination with an error).
`try` function, which is similar to `spawn`, but immediately blocks and waits
for the child task to finish. `try` returns a value of type
`Result<T, Box<Any + Send>>`. `Result` is an `enum` type with two variants:
`Ok` and `Err`. In this case, because the type arguments to `Result` are `int`
and `()`, callers can pattern-match on a result to check whether it's an `Ok`
result with an `int` field (representing a successful result) or an `Err` result
(representing termination with an error).

```{rust}
# use std::task;
Expand Down Expand Up @@ -369,4 +369,4 @@ the entire program (perhaps you're writing an assert which, if it trips,
indicates an unrecoverable logic error); in other cases you might want to
contain the failure at a certain boundary (perhaps a small piece of input from
the outside world, which you happen to be processing in parallel, is malformed
and its processing task can't proceed).
such that the processing task cannot proceed).