There's more...

A channel is not Sync and, as such, can only be moved across channels but not shared between them. If you need the channel to be Sync you can use std::sync::mpsc::sync_channel, which blocks when a buffer of unanswered messages is full. An example for when this might be necessary is when a web framework offers to manage your types but only works with Sync structs. You can read more on Sync in the recipe Atomically access primitives.

The mpsc channels, as their name suggests, allow many senders but only one receiver. Most of the time, this will be good enough, but if you find yourself needing the exact opposite, as in one sender and multiple receivers, check out Sean McArthur's spmc crate at https://crates.io/crates/spmc, which provides you with Single-producer, multi-consumer channels.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.220.22