Skip to content

Commit

Permalink
feat(use_channel): try_send (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 authored Jun 27, 2023
1 parent 6b3350f commit 095efca
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/utils/channel/use_channel.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use async_broadcast::{broadcast, InactiveReceiver, Receiver, SendError, Sender};
use async_broadcast::{broadcast, InactiveReceiver, Receiver, SendError, Sender, TrySendError};
use dioxus::prelude::ScopeState;
use uuid::Uuid;

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

impl<MessageType: Clone> UseChannel<MessageType> {
/// Tries to send a message to all listeners of the channel.
pub fn try_send(&self, msg: impl Into<MessageType>) -> Result<(), TrySendError<MessageType>> {
self.sender.try_broadcast(msg.into()).map(|_| ())
}

/// Sends a message to all listeners of the channel.
pub async fn send(&self, msg: impl Into<MessageType>) -> Result<(), SendError<MessageType>> {
self.sender.broadcast(msg.into()).await.map(|_| ())
Expand Down

0 comments on commit 095efca

Please sign in to comment.