Skip to content

Ch 21.3 Final code does not match step for JoinHandle Option #4642

@ekcom

Description

@ekcom
  • I have searched open and closed issues and pull requests for duplicates, using these search terms:
    • 21.3
    • 21 final code
  • I have checked the latest main branch to see if this has already been fixed, in this file:
    • listings/ch21-web-server/no-listing-07-final-code/src/lib.rs

URL to the section(s) of the book with this problem:
https://doc.rust-lang.org/book/ch21-03-graceful-shutdown-and-cleanup.html

Description of the problem:

Section 21.3 "Implementing the Drop Trait on ThreadPool" mentions:

However, the only time this would come up would be when dropping the Worker[...]
In this case, a better alternative exists: the Vec::drain method[...]

and then provides this snippet:

        for worker in self.workers.drain(..) {
            println!("Shutting down worker {}", worker.id);

            worker.thread.join().unwrap();
        }

Listing 21-23 reflects this usage of drain instead of making thread an Option, but the final code does not.

Suggested fix:
Correct final code to use the Vec::drain strategy and not make thread and Option (as initiated in #3248).

I will open a PR to address this within the day.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions