Trait reactive_messaging::prelude::ChannelProducer
source · pub trait ChannelProducer<'a, ItemType, DerivedItemType>where
ItemType: Debug + Send + Sync,
DerivedItemType: 'a + Debug,{
// Required methods
fn send(&self, item: ItemType) -> RetryResult<(), ItemType, (), ()>;
fn send_with<F>(&self, setter: F) -> RetryResult<(), F, (), ()>
where F: FnOnce(&mut ItemType);
// Provided method
fn send_derived(&self, _derived_item: &DerivedItemType) -> bool { ... }
}Expand description
Defines how to send events (to a [Uni] or [Multi]).
Required Methods§
sourcefn send(&self, item: ItemType) -> RetryResult<(), ItemType, (), ()>
fn send(&self, item: ItemType) -> RetryResult<(), ItemType, (), ()>
Similar to Self::send_with(), but for sending the already-built item.
See there for how to deal with the returned type.
IMPLEMENTORS: #[inline(always)]
sourcefn send_with<F>(&self, setter: F) -> RetryResult<(), F, (), ()>where
F: FnOnce(&mut ItemType),
fn send_with<F>(&self, setter: F) -> RetryResult<(), F, (), ()>where F: FnOnce(&mut ItemType),
Calls setter, passing a slot so the payload may be filled there, then sends the event through this channel asynchronously.
The returned type is conversible to Result<(), F> by calling .into() on it, returning Err<setter> when the buffer is full,
to allow the caller to try again; otherwise you may add any retrying logic using the keen-retry crate’s API like in:
xxxx.send_with(|slot| *slot = 42)
.retry_with(|setter| xxxx.send_with(setter))
.spinning_until_timeout(Duration::from_millis(300), ()) // go see the other options
.map_errors(|_, setter| (setter, _), |e| e) // map the unconsumed `setter` payload into `Err(setter)` when converting to `Result` ahead
.into()?;
NOTE: this type may allow the compiler some extra optimization steps when compared to Self::send(). When tuning for performance, it is advisable to try this method IMPLEMENTORS: #[inline(always)]
Provided Methods§
sourcefn send_derived(&self, _derived_item: &DerivedItemType) -> bool
fn send_derived(&self, _derived_item: &DerivedItemType) -> bool
For channels that stores the DerivedItemType instead of the ItemType, this method may be useful
– for instance: if the Stream consumes Arc<String> (the derived item type) and the channel is for Strings, With this method one may send an Arc directly.
The default implementation, though, is made for types that don’t have a derived item type.
IMPLEMENTORS: #[inline(always)]