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.
Description
In the Async in Depth documentation, this part doesn't compile:
For what I understand, it is because of
ArcWake
needsTask
to beSync
, andmpsc::Sender
is onlySend
, notSync
.I found a quick workaround with wrapping the
Sender
in aMutex
so all members ofTask
areSync
.I can submit a two liners PR if you fancy.