Struct Queue

Source
pub struct Queue(/* private fields */);
Expand description

Shared Queues in proxy-wasm are a FIFO MPMC queue with no message duplication. Any WASM VM can resolve a queue or register new ones in their own VM ID. Any WASM VM can dequeue data, which will globally dequeue that item. Messages are not replicated to each WASM VM. When broadcasting data to many WASM VMs, it’s advised to have a scheme where each thread can register it’s own inbound queue, then enqueue the name of said queue to the centralized source of data. That source then enqueues to each WASM VM’s queue individually.

Implementations§

Source§

impl Queue

Source

pub fn register(name: impl AsRef<str>) -> Result<Self, Status>

Registers a new queue under a given name. Names are globally unique underneath a single VM ID. Re-registering the same name from any WASM VM in the same VM ID will overwrite the previous registration of that name, and is not advised.

Source

pub fn resolve( vm_id: impl AsRef<str>, name: impl AsRef<str>, ) -> Result<Option<Self>, Status>

Resolves an existing queue for a given name in the given VM ID.

Source

pub fn dequeue(&self) -> Result<Option<Vec<u8>>, Status>

Remove an item from this queue, if any is present. Returns Ok(None) when no data is enqueued. Note that this is not VM-local and any message can only be received by one dequeue operation anywhere.

Source

pub fn enqueue(&self, value: impl AsRef<[u8]>) -> Result<(), Status>

Enqueues a new item into this queue.

Source

pub fn on_enqueue<R: RootContext>( self, callback: impl FnMut(&mut R, Queue) + 'static, ) -> Self

Registers a callback that is called whenever data is available in the queue to be dequeued. Only one of on_enqueue or on_receive can be set at the same time.

Source

pub fn on_receive<R: RootContext>( self, callback: impl FnMut(&mut R, Queue, Vec<u8>) + 'static, ) -> Self

Registers a callback that is called whenever data is available in the queue to be dequeued. Also dequeues anything on the queue. It may call the callback multiple times for each item, if multiple are present. Only one of on_enqueue or on_receive can be set at the same time.

Trait Implementations§

Source§

impl Clone for Queue

Source§

fn clone(&self) -> Queue

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl PartialEq<Queue> for u32

Source§

fn eq(&self, other: &Queue) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<u32> for Queue

Source§

fn eq(&self, other: &u32) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for Queue

Source§

fn eq(&self, other: &Queue) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Queue

Source§

impl Eq for Queue

Source§

impl StructuralPartialEq for Queue

Auto Trait Implementations§

§

impl Freeze for Queue

§

impl RefUnwindSafe for Queue

§

impl Send for Queue

§

impl Sync for Queue

§

impl Unpin for Queue

§

impl UnwindSafe for Queue

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.