Skip to content

Commit 3677a1f

Browse files
committed
Rollup merge of #27924 - pornel:bookthreadjoin, r=steveklabnik
The chapter on concurrency has two examples that both start with: let something = thread::spawn(… but the returned values have different types, because the second example has `.join()` at the end of the expression. I haven't noticed that join at first, and was wondering how is that possible that the result can have `.is_err()` and `.join()` methods. I've changed the second example to have the same structure as the first, so they're easy to compare.
2 parents b3e9615 + d112274 commit 3677a1f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/doc/trpl/concurrency.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,14 @@ threads as a simple isolation mechanism:
343343
```rust
344344
use std::thread;
345345

346-
let result = thread::spawn(move || {
346+
let handle = thread::spawn(move || {
347347
panic!("oops!");
348-
}).join();
348+
});
349+
350+
let result = handle.join();
349351

350352
assert!(result.is_err());
351353
```
352354

353-
Our `Thread` gives us a `Result` back, which allows us to check if the thread
355+
`Thread.join()` gives us a `Result` back, which allows us to check if the thread
354356
has panicked or not.

0 commit comments

Comments
 (0)