1tgr / rust-websocket-lite

A fast, low-overhead WebSocket client
MIT License
115 stars 17 forks source link

RFC: Split sync and async crates #329

Open 1tgr opened 1 year ago

1tgr commented 1 year ago

I'd like to get some opinions on splitting the websocket-lite crate into two halves:

On #230, @Gelbpunkt requested to remove the synchronous functions but I said they were useful: non-futures-based code is easier to optimise, and works fine provided you can dedicate a thread to a connection.

On #204, @jjl suggested that we could remove the tokio dependencies for apps that only use the synchronous code.

I propose that the websocket-lite and websocket-lite-sync crates have an identical API: for example, both crates expose a method ClientBuilder::connect, instead of separate connect and async_connect methods.

The websocket-codec crate gains a tokio feature, which causes it to impl the Encoder and Decoder traits from tokio_util. The crate gets its own Encoder and Decoder traits, regardless of the tokio feature.

Rather than copying and pasting the source code into two crates, I was considering using the im and im-rc crates' trick to compile two crates from one source tree.

1tgr commented 1 year ago

As described, this change causes disruption to current async and synchronous users of websocket-lite:

Alternatively, websocket-lite could contain the synchronous code, and we could have a new tokio-websocket-lite for the async code: