pub struct RocketMQBlockingQueue<T> { /* private fields */ }
Expand description
A thread-safe bounded blocking queue. To replace Java LinkedBlockingQueue
.
This queue allows multiple producers and consumers to add and remove items
concurrently. It uses a tokio::sync::Mutex
to ensure mutual exclusion and
a tokio::sync::Notify
to notify waiting tasks.
Implementations§
Source§impl<T> BlockingQueue<T>
impl<T> BlockingQueue<T>
Sourcepub async fn put(&self, item: T)
pub async fn put(&self, item: T)
Adds an item to the queue, waiting if necessary for space to become available.
This method will block the current task until space is available in the queue.
§Arguments
item
- The item to be added to the queue.
Sourcepub async fn offer(&self, item: T, timeout: Duration) -> bool
pub async fn offer(&self, item: T, timeout: Duration) -> bool
Attempts to add an item to the queue within a specified timeout.
This method will block the current task until space is available in the queue or the timeout is reached.
§Arguments
item
- The item to be added to the queue.timeout
- The maximum duration to wait for space to become available.
§Returns
true
if the item was added to the queue, false
if the timeout was reached.
Sourcepub async fn take(&self) -> T
pub async fn take(&self) -> T
Removes and returns an item from the queue, waiting if necessary until an item is available.
This method will block the current task until an item is available in the queue.
§Returns
The item removed from the queue.
Sourcepub async fn poll(&self, timeout: Duration) -> Option<T>
pub async fn poll(&self, timeout: Duration) -> Option<T>
Attempts to remove and return an item from the queue within a specified timeout.
This method will block the current task until an item is available in the queue or the timeout is reached.
§Arguments
timeout
- The maximum duration to wait for an item to become available.
§Returns
Some(item)
if an item was removed from the queue, None
if the timeout was reached.
Sourcepub async fn try_poll(&self) -> Option<T>
pub async fn try_poll(&self) -> Option<T>
Attempts to remove and return an item from the queue without waiting.
This method acquires a lock on the queue and attempts to remove an item. If the queue is empty, it will notify waiting tasks.
§Returns
Some(item)
if an item was removed from the queue, None
if the queue was empty.