April 2026
Intermediate
631 pages
16h 20m
English
In this section, we’ll illustrate a use case for threads. We hope this use case will provide some intuitive wisdom regarding the advantages of concurrent execution of code using threads over sequential execution.
Our example involves web scraping, which refers to the extraction of data from a webpage. The goal in this example is to extract textual information from webpages using threads and also using conventional sequential code and then compare the time required by each of these coding approaches.
Consider the code shown in Listing 14.52.
use std::sync::{mpsc, Arc, Mutex};use std::thread;use std::time::{Duration, Instant};use ureq::{Agent, AgentBuilder};fn main() -> Result<(), ureq::Error> { let webpages ...
Read now
Unlock full access