Skip to content

Commit 095efca

Browse files
authored
feat(use_channel): try_send (#10)
1 parent 6b3350f commit 095efca

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/utils/channel/use_channel.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use async_broadcast::{broadcast, InactiveReceiver, Receiver, SendError, Sender};
1+
use async_broadcast::{broadcast, InactiveReceiver, Receiver, SendError, Sender, TrySendError};
22
use dioxus::prelude::ScopeState;
33
use uuid::Uuid;
44

@@ -17,6 +17,11 @@ impl<T: Clone> PartialEq for UseChannel<T> {
1717
}
1818

1919
impl<MessageType: Clone> UseChannel<MessageType> {
20+
/// Tries to send a message to all listeners of the channel.
21+
pub fn try_send(&self, msg: impl Into<MessageType>) -> Result<(), TrySendError<MessageType>> {
22+
self.sender.try_broadcast(msg.into()).map(|_| ())
23+
}
24+
2025
/// Sends a message to all listeners of the channel.
2126
pub async fn send(&self, msg: impl Into<MessageType>) -> Result<(), SendError<MessageType>> {
2227
self.sender.broadcast(msg.into()).await.map(|_| ())

0 commit comments

Comments
 (0)