Skip to content

Commit

Permalink
Merge pull request #191 from fbrouille/stream_with_unbounded_channel
Browse files Browse the repository at this point in the history
AsyncClient::get_stream() support unbounded channel
  • Loading branch information
fpagliughi authored Mar 9, 2023
2 parents d2eef1a + 8375060 commit fd60f84
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/async_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1108,12 +1108,19 @@ impl AsyncClient {
/// gets disconnected, it will insert `None` into the channel to signal
/// the app about the disconnect.
///
/// The stream will rely on a bounded channel with the given buffer
/// capacity if 'buffer_sz' is 'Some' or will rely on an unbounded channel
/// if 'buffer_sz' is 'None'.
///
/// It's a best practice to open the stream _before_ connecting to the
/// server. When using persistent (non-clean) sessions, messages could
/// arriving as soon as the connection is made - even before the
/// connect() call returns.
pub fn get_stream(&mut self, buffer_sz: usize) -> AsyncReceiver<Option<Message>> {
let (tx, rx) = async_channel::bounded(buffer_sz);
pub fn get_stream(&mut self, buffer_sz: Option<usize>) -> AsyncReceiver<Option<Message>> {
let (tx, rx) = match buffer_sz {
None => async_channel::unbounded(),
Some(capacity) => async_channel::bounded(capacity),
};

// Make sure at least the low-level connection lost handlers are in
// place to notify us when the connection is lost (sends a 'None' to
Expand Down

0 comments on commit fd60f84

Please sign in to comment.