Open flxo opened 8 months ago
Going by how other libraries handle this, I think we should deprecate Async
/Client::new(opt, cap)
and just have an EventLoop::new(opt, cap) -> (AsyncClient, EventLoop)
and EventLoop::new_sync(opt, cap) -> (Client, EventLoop)
From an even higher perspective I don't get why there's a separation between AsyncClient
and EventLoop
. Maybe a relict from the sync versions and the intention is to keep them close to each other.
Why not:
AsyncClient::new(opt) -> AsyncClient;
impl Stream<Item = Result<Event, ConnectionError> for AsyncClient { ... }
impl Sink<Request, Error = ConnectionError> for AsyncClient { ... }
I see the following advantages:
Stream
/Sink
is commonly known how to use and there a are tons of combinatorspoll
the event loop.The Sink
impl is trivial since the used channel implementation implements Sink
for Sender
. The Stream
part is also not that hard if the events
(VecDeque) in MqttState
is replaced with a channel. A rough draft is here.
If the separation is needed there's StreamExt::split
I don't get why there's a separation between AsyncClient and EventLoop
The initial design was simple, an eventloop, that gets driven by calls to EventLoop.poll()
, where multiple threads could connect to and send data over an mpsc channel. we had not thought about designing it as a stream + sink setup, maybe we could plan this for the v1.0.0
The async v5 client implementation checks for errors when receiving from the request channel. The only error that can happen here (with flume) is RecvError (disconnected):
An error that may be emitted when attempting to wait for a value on a receiver when all senders are dropped and there are no more messages in the channel.
.EventLoop holds a sender handle to this channel. This error condition can never happen. The implementation is confusing.
During the construction of the
AsyncClient
the tx handle is cloned.A easy fix could be to return the sending half from
EventLoop::new
(and update the visibility) and move it into theAsyncClient
: