mnetship / ratsio

NATS & NATS Streaming Server client library for Rust
MIT License
50 stars 22 forks source link

Switch to async synchronization primitives #13

Closed dbcfd closed 4 years ago

dbcfd commented 4 years ago

PR for #12

ebkalderon commented 4 years ago

Looks like this is mostly done in master by https://github.com/mnetship/ratsio/commit/c7ef48c60a050265b2964d56333742e7fbaeea62, but it seems that it was missed in NatsClientInner::on_connect (I'm ignoring the std::sync::Mutex usage in src/nuid.rs because it doesn't look heavily IO-bound). CC @awesomike

I also wonder why std::sync::RwLock was replaced with futures::sync::Mutex instead of tokio::sync::RwLock? 🤔 This library seems to already be heavily invested in tokio, with heavy structural reliance on tokio::spawn and tokio::io::{AsyncRead, AsyncWrite}, so why not go all-in? It's not a huge deal, though. The most important thing is avoiding stalling the executor with blocking calls; the choice between an async-aware Mutex or RwLock is arguably less important.