Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 1 addition & 6 deletions listings/ch21-web-server/listing-21-17/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,11 @@ impl ThreadPool {
// ANCHOR: here
}

// --snip--

// ANCHOR_END: here

struct Worker {
id: usize,
thread: thread::JoinHandle<()>,
thread: thread::JoinHandle<mpsc::Receiver<Job>>,
}

// ANCHOR: here
impl Worker {
fn new(id: usize, receiver: mpsc::Receiver<Job>) -> Worker {
let thread = thread::spawn(|| {
Expand Down
6 changes: 1 addition & 5 deletions listings/ch21-web-server/listing-21-18/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,11 @@ impl ThreadPool {
// ANCHOR: here
}

// --snip--

// ANCHOR_END: here
struct Worker {
id: usize,
thread: thread::JoinHandle<()>,
thread: thread::JoinHandle<Arc<Mutex<mpsc::Receiver<Job>>>>,
}

// ANCHOR: here
impl Worker {
fn new(id: usize, receiver: Arc<Mutex<mpsc::Receiver<Job>>>) -> Worker {
// --snip--
Expand Down
4 changes: 3 additions & 1 deletion src/ch21-02-multithreaded.md
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,9 @@ closure. The code in Listing 21-17 won’t quite compile yet.
</Listing>

We’ve made some small and straightforward changes: we pass the receiver into
`Worker::new`, and then we use it inside the closure.
`Worker::new`, and then we use it inside the closure. This causes the type returned
from `thread::spawn` to change too. So, we also updated the type for the `thread`
field in the `Worker` struct.

When we try to check this code, we get this error:

Expand Down
Loading