pub struct Consumer { /* private fields */ }Expand description
Thread-safe Consumer type with a group number representing the consumer group.
Use try_clone to make copies of the Consumer in the same group or use subscribe on a producer to create new Consumers.
let mut tx = disk_chan::new("foo", 2_u32.pow(24), 1).await?;
let mut rx = tx.subscribe(0).await?;
let mut rx2 = rx.try_clone().await?;
let msg = loop {
match rx.recv().await {
Some(msg) => break msg,
None => rx.next_page().await?,
}
};Implementations§
Source§impl Consumer
impl Consumer
Sourcepub async fn try_clone(&self) -> Result<Self, Error>
pub async fn try_clone(&self) -> Result<Self, Error>
Attempts to clone the current Consumer with the same group.
This can potentially fail to do interactions with the file system, but should be near impossible with correct usage.
Sourcepub async fn recv(&self) -> Option<&[u8]>
pub async fn recv(&self) -> Option<&[u8]>
Asynchronously receives the next message in the consumer group.
Returns None when the consumer has read all messages from the current page, and the user must call next_page to continue reading.
This is necessary due to the message’s lifetime being tied to the consumer’s current page so it must not be accessed after a call to next_page. Thus, it is up to the user to ensure the compiler is happy with lifetimes.
let mut tx = disk_chan::new("foo", 2_u32.pow(24), 1).await?;
let mut rx = tx.subscribe(0).await?;
let mut rx2 = rx.try_clone().await?;
let msg = loop {
match rx.recv().await {
Some(msg) => break msg,
None => rx.next_page().await?,
}
};Sourcepub async fn next_page(&mut self) -> Result<(), Error>
pub async fn next_page(&mut self) -> Result<(), Error>
Sets the internal page to the next available one.
Should be called after recv returns None.
let mut tx = disk_chan::new("foo", 2_u32.pow(24), 1).await?;
let mut rx = tx.subscribe(0).await?;
let mut rx2 = rx.try_clone().await?;
let msg = loop {
match rx.recv().await {
Some(msg) => break msg,
None => rx.next_page().await?,
}
};