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

Provide a simple async fn send method for better interoperability with futures-lite based facilities #142

Open
stackinspector opened this issue Nov 3, 2024 · 3 comments

Comments

@stackinspector
Copy link

Smol(futures-lite)'s guys think that futures_sink::Sink (till v0.3) is a legacy API and excluded related APIs in futures-lite intentionally. They prefer a simple async fn send API.
Before a new simple Sink API is normalized, I suggest considering implementing a simple async fn send method:

impl<S> WebSocketStream<S> {
    /// Simple send method to replace `futures_sink::Sink` (till v0.3).
    pub async fn send(&mut self, msg: Message) -> Result<(), WsError>
    where
        S: AsyncRead + AsyncWrite + Unpin,
    {
        // Example to make it work. A simpler internal way can be used to implement it.
        SinkExt::send(self, msg).await
    }
}

In an ideal world, the send method would be called even if the SinkExt was introduced. I'm not sure if there would be additional problems if a method name is duplicated with a method in trait.
cc smol-rs/futures-lite#111 smol-rs/futures-lite#112

@stackinspector
Copy link
Author

smol/futures-lite#112 has been merged.
Final document: https://github.com/smol-rs/futures-lite/blob/master/FEATURES.md

@sdroege
Copy link
Owner

sdroege commented Nov 24, 2024

I'm also not a fan of the Sink API. Having a simple send() function like this would seem like a good idea. Do you want to provide a PR for adding it?

@stackinspector
Copy link
Author

I tried but I realized I'm not very good at handling details of async primitives. Considering code robustness, it might be a good idea to assign community members who's more experienced.

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