tokio-rs / website

Website for the Tokio project
https://tokio.rs
MIT License
227 stars 328 forks source link

Documentation: MiniTokio doesn't compile #734

Closed lsioctl closed 7 months ago

lsioctl commented 7 months ago

Description

In the Async in Depth documentation, this part doesn't compile:

struct Task {
    // The `Mutex` is to make `Task` implement `Sync`. Only
    // one thread accesses `future` at any given time. The
    // `Mutex` is not required for correctness. Real Tokio
    // does not use a mutex here, but real Tokio has
    // more lines of code than can fit in a single tutorial
    // page.
    future: Mutex<Pin<Box<dyn Future<Output = ()> + Send>>>,
    executor: mpsc::Sender<Arc<Task>>,
}

For what I understand, it is because of ArcWake needs Task to be Sync, and mpsc::Sender is only Send, not Sync.

I found a quick workaround with wrapping the Sender in a Mutex so all members of Task are Sync.

I can submit a two liners PR if you fancy.

Darksonn commented 7 months ago

Actually, mpsc::Sender is now Sync as of rustc 1.72.0. Please see #727.

lsioctl commented 7 months ago

Completely missed that ! Sorry and thank you.

Darksonn commented 7 months ago

No worries. Thank you for going to the effort to let us know about a potential issue.