Struct RocketMQBlockingQueue

Source
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>

Source

pub fn new(capacity: usize) -> Self

Creates a new BlockingQueue with the specified capacity.

§Arguments
  • capacity - The maximum number of items the queue can hold.
§Returns

A new instance of BlockingQueue.

Source

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.
Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn is_empty(&self) -> bool

Checks if the queue is empty.

This method acquires a lock on the queue and checks if it contains any items.

§Returns

true if the queue is empty, false otherwise.

Auto Trait Implementations§

§

impl<T> !Freeze for BlockingQueue<T>

§

impl<T> !RefUnwindSafe for BlockingQueue<T>

§

impl<T> Send for BlockingQueue<T>
where T: Send,

§

impl<T> Sync for BlockingQueue<T>
where T: Send,

§

impl<T> Unpin for BlockingQueue<T>
where T: Unpin,

§

impl<T> !UnwindSafe for BlockingQueue<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more