pub struct Channel<T> { /* private fields */ }Expand description
Defines one durable FIFO queue of typed messages.
Add the Channel to crate::PersistenceSchema. Clients and handlers may publish messages;
Steps create Condition values that wait for queue-size bounds and read the messages consumed
by the satisfied condition.
Handler publications and deletions are staged until successful return. A satisfied wait
consumes messages before Execute; it does not combine that consumption with later publications
into one transaction. Pending-message reads are snapshots that other handlers can change.
Select pending-message loads explicitly. Use transactional RPC execution for atomic deletion
and publication, and a shared Attribute lock when all cooperating writers must serialize a
decision about the queue. T must implement Value when publishing or reading messages.
Declare reusable definitions as module-level std::sync::LazyLock statics.
§Examples
use dex_sdk::{Channel, Wait};
let approvals = Channel::<String>::new("approvals");
let wait = Wait::until(approvals.for_one());Implementations§
Source§impl<T> Channel<T>
impl<T> Channel<T>
Sourcepub fn new(name: impl Into<String>) -> Self
pub fn new(name: impl Into<String>) -> Self
Defines a Channel with a stable name.
Slash is prohibited because it is a reserved character.
Sourcepub fn publish(&self, context: &mut Context, value: T) -> HandlerResult<()>where
T: Value,
pub fn publish(&self, context: &mut Context, value: T) -> HandlerResult<()>where
T: Value,
Stages one message from the current Step or RPC invocation.
§Errors
Returns a crate::HandlerError when value cannot be encoded.
Sourcepub fn delete(
&self,
context: &mut Context,
message_id: &str,
) -> HandlerResult<()>
pub fn delete( &self, context: &mut Context, message_id: &str, ) -> HandlerResult<()>
Stages best-effort deletion of one pending message from a handler.
Sourcepub fn size(&self, context: &Context) -> HandlerResult<usize>
pub fn size(&self, context: &Context) -> HandlerResult<usize>
Returns the invocation snapshot’s queued-message count.
Sourcepub fn pending_messages(
&self,
context: &Context,
) -> HandlerResult<Vec<ChannelMessage<T>>>where
T: Value,
pub fn pending_messages(
&self,
context: &Context,
) -> HandlerResult<Vec<ChannelMessage<T>>>where
T: Value,
Returns loaded pending messages from the invocation snapshot in FIFO order.
§Errors
Returns a crate::HandlerError when this Channel was not selected by the handler options
or when decoding fails.
Sourcepub fn find_pending_message(
&self,
context: &Context,
message_id: &str,
) -> HandlerResult<Option<ChannelMessage<T>>>where
T: Value,
pub fn find_pending_message(
&self,
context: &Context,
message_id: &str,
) -> HandlerResult<Option<ChannelMessage<T>>>where
T: Value,
Finds one pending message by its Dex-assigned ID.
Returns Ok(None) when the loaded snapshot does not contain message_id.
§Errors
Returns the same errors as Self::pending_messages.
Sourcepub fn condition_results(&self, context: &Context) -> HandlerResult<Vec<T>>where
T: Value,
pub fn condition_results(&self, context: &Context) -> HandlerResult<Vec<T>>where
T: Value,
Decodes messages consumed by this Channel’s satisfied condition.
§Errors
Returns a crate::HandlerError when a message cannot be decoded.
Sourcepub fn for_one(&self) -> Condition
pub fn for_one(&self) -> Condition
Creates a condition that consumes exactly one queued message.
Sourcepub fn for_n(&self, count: usize) -> Condition
pub fn for_n(&self, count: usize) -> Condition
Creates a condition that consumes exactly count queued messages.
Sourcepub fn at_least(&self, count: usize) -> Condition
pub fn at_least(&self, count: usize) -> Condition
Creates a condition satisfied when at least count messages are queued.
Sourcepub fn at_most(&self, count: usize) -> Condition
pub fn at_most(&self, count: usize) -> Condition
Creates a non-blocking condition consuming up to count queued messages.
When its surrounding Wait completes, it consumes messages queued then. An empty queue yields no messages.
Sourcepub fn range(
&self,
at_least: Option<usize>,
at_most: Option<usize>,
) -> Condition
pub fn range( &self, at_least: Option<usize>, at_most: Option<usize>, ) -> Condition
Creates a condition that waits for the lower bound, then consumes up to the upper bound.
Omitting the lower bound makes the condition complete immediately. Consumption uses only messages queued when the condition completes.
Sourcepub fn when_empty(&self) -> ChannelGuard
pub fn when_empty(&self) -> ChannelGuard
Creates a guard used by conditional Flow completion to require an empty queue.
Trait Implementations§
Auto Trait Implementations§
impl<T> Forget for Channel<T>
impl<T> Freeze for Channel<T>
impl<T> RefUnwindSafe for Channel<T>
impl<T> Send for Channel<T>
impl<T> Sync for Channel<T>
impl<T> Unpin for Channel<T>
impl<T> UnsafeUnpin for Channel<T>
impl<T> UnwindSafe for Channel<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request