pub enum EventSender {
Unbounded(UnboundedSender<Msg>),
Bounded(Sender<Msg>),
}Expand description
Event sender abstraction that can be either bounded or unbounded.
EventSender provides a unified interface for sending messages through
either bounded or unbounded channels. This abstraction allows the framework
to switch between different channel types without changing the API.
§Examples
use bubbletea_rs::event::{EventSender, Msg};
use tokio::sync::mpsc;
// Create from unbounded channel
let (tx, _rx) = mpsc::unbounded_channel::<Msg>();
let sender = EventSender::from_unbounded(tx);
// Send a message
let msg: Msg = Box::new("Hello");
sender.send(msg).unwrap();Variants§
Unbounded(UnboundedSender<Msg>)
Unbounded channel sender used for unlimited-capacity message delivery.
Bounded(Sender<Msg>)
Bounded channel sender that applies backpressure when full.
Implementations§
Source§impl EventSender
impl EventSender
Sourcepub fn send(&self, msg: Msg) -> Result<(), Error>
pub fn send(&self, msg: Msg) -> Result<(), Error>
Send a message through the channel.
Attempts to send a message through the underlying channel. For unbounded channels, this will only fail if the receiver has been dropped. For bounded channels, this may also fail due to backpressure (channel full).
§Arguments
msg- The message to send
§Returns
Returns Ok(()) if the message was sent successfully, or an error if:
- The channel is closed (
Error::ChannelClosed) - The channel is full (
Error::ChannelFull) for bounded channels
§Examples
use bubbletea_rs::event::{EventSender, Msg};
use tokio::sync::mpsc;
let (tx, _rx) = mpsc::unbounded_channel::<Msg>();
let sender = EventSender::from_unbounded(tx);
let msg: Msg = Box::new(42);
match sender.send(msg) {
Ok(()) => println!("Message sent!"),
Err(e) => eprintln!("Failed to send: {}", e),
}Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Check if the sender is closed.
Returns true if the receiver side of the channel has been dropped,
meaning that any future send operations will fail.
§Returns
true if the channel is closed, false otherwise
§Examples
use bubbletea_rs::event::{EventSender, Msg};
use tokio::sync::mpsc;
let (tx, rx) = mpsc::unbounded_channel::<Msg>();
let sender = EventSender::from_unbounded(tx);
assert!(!sender.is_closed());
drop(rx); // Drop the receiver
assert!(sender.is_closed());Sourcepub fn from_unbounded(tx: UnboundedSender<Msg>) -> Self
pub fn from_unbounded(tx: UnboundedSender<Msg>) -> Self
Create an EventSender from an UnboundedSender (for backward compatibility).
This method creates an EventSender wrapping an unbounded channel sender.
Unbounded channels have unlimited capacity and never apply backpressure.
§Arguments
tx- The unbounded sender to wrap
§Returns
An EventSender that uses the provided unbounded channel
§Examples
use bubbletea_rs::event::{EventSender, Msg};
use tokio::sync::mpsc;
let (tx, _rx) = mpsc::unbounded_channel::<Msg>();
let sender = EventSender::from_unbounded(tx);Sourcepub fn from_bounded(tx: Sender<Msg>) -> Self
pub fn from_bounded(tx: Sender<Msg>) -> Self
Create an EventSender from a bounded Sender (for testing).
This method creates an EventSender wrapping a bounded channel sender.
Bounded channels have limited capacity and will apply backpressure when full.
This is primarily used in testing scenarios to verify behavior under
backpressure conditions.
§Arguments
tx- The bounded sender to wrap
§Returns
An EventSender that uses the provided bounded channel
§Examples
use bubbletea_rs::event::{EventSender, Msg};
use tokio::sync::mpsc;
let (tx, _rx) = mpsc::channel::<Msg>(10); // Capacity of 10
let sender = EventSender::from_bounded(tx);Trait Implementations§
Source§impl Clone for EventSender
impl Clone for EventSender
Source§fn clone(&self) -> EventSender
fn clone(&self) -> EventSender
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more