Why std's Receiver is not Sync, but tokio/futures's Receiver is Sync?

Basically, it has to do with how they prevent you from having multiple receivers. (mpsc means multi-producer single-consumer)

For the std channel, the recv method takes &self but the type is not Sync so you can't call recv in parallel.

For the Tokio channel, the recv method takes &mut self, so even though the type is Sync, you can't call recv in parallel.

To be clear, I believe it is considered an API mistake to go with &self and !Sync for the std channel, and that &mut self is the better route.

7 Likes