Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SendError cannot be sent between threads? #116

Open
stevefan1999-personal opened this issue Dec 23, 2022 · 1 comment
Open

SendError cannot be sent between threads? #116

stevefan1999-personal opened this issue Dec 23, 2022 · 1 comment

Comments

@stevefan1999-personal
Copy link

error[E0277]: `SinkItem` cannot be shared between threads safely
   --> tarpc\src\transport\channel.rs:130:45
    |
130 |             .map_err(|e| ChannelError::Send(Box::new(e)))
    |                                             ^^^^^^^^^^^ `SinkItem` cannot be shared between threads safely
    |
    = note: required because it appears within the type `flume::SendError<SinkItem>`
    = note: required for the cast from `flume::SendError<SinkItem>` to the object type `dyn StdError + std::marker::Send + Sync`
help: consider restricting type parameter `SinkItem`
    |
123 | impl<Item, SinkItem: std::marker::Sync> Sink<SinkItem> for Channel<Item, SinkItem> {
    |                    +++++++++++++++++++

This is what ChannelError looks like:

/// Errors that occur in the sending or receiving of messages over a channel.
#[derive(thiserror::Error, Clone, PartialEq, Eq, Debug)]
pub enum ChannelError {
    /// An error occurred sending over the channel.
    #[error("an error occurred sending over the channel")]
    Send(#[from] Box<dyn Error + Send + Sync + 'static>),
    #[error("the channel is closed and cannot accept new items for sending")]
    Closed
}

So it seems like I have to limit the bound of SinkItem to Send + Sync? but far as I know futures::channel::mpsc::Sender does not require that

@zesterer
Copy link
Owner

That same requirement definitely exists on futures::channel::mpsc::Sender: the channel has the capacity to send data between threads, so that data must be thread-safe. It might be that the requirement is simply on an impl in futures, but it'll still be there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants