summaryrefslogtreecommitdiffstats
path: root/futures/src/subscription
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-06-04 23:20:33 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-06-10 22:03:46 +0200
commite400f972c1fe6fa4f70f8cfe559ded680e6cf740 (patch)
tree3f026bfdf489c367ff007b6513752c8060014a4d /futures/src/subscription
parent49affc44ff57ad879a73d9b4d329863d6f4b1d2c (diff)
downloadiced-e400f972c1fe6fa4f70f8cfe559ded680e6cf740.tar.gz
iced-e400f972c1fe6fa4f70f8cfe559ded680e6cf740.tar.bz2
iced-e400f972c1fe6fa4f70f8cfe559ded680e6cf740.zip
Introduce `window::Id` to `Event` subscriptions
And remove `window::Id` from `Event` altogether.
Diffstat (limited to '')
-rw-r--r--futures/src/subscription.rs11
-rw-r--r--futures/src/subscription/tracker.rs16
2 files changed, 20 insertions, 7 deletions
diff --git a/futures/src/subscription.rs b/futures/src/subscription.rs
index 93e35608..79cea6ed 100644
--- a/futures/src/subscription.rs
+++ b/futures/src/subscription.rs
@@ -4,6 +4,7 @@ mod tracker;
pub use tracker::Tracker;
use crate::core::event::{self, Event};
+use crate::core::window;
use crate::futures::{Future, Stream};
use crate::{BoxStream, MaybeSend};
@@ -15,7 +16,7 @@ use std::hash::Hash;
/// A stream of runtime events.
///
/// It is the input of a [`Subscription`].
-pub type EventStream = BoxStream<(Event, event::Status)>;
+pub type EventStream = BoxStream<(Event, event::Status, window::Id)>;
/// The hasher used for identifying subscriptions.
pub type Hasher = rustc_hash::FxHasher;
@@ -289,7 +290,9 @@ where
pub(crate) fn filter_map<I, F, Message>(id: I, f: F) -> Subscription<Message>
where
I: Hash + 'static,
- F: Fn(Event, event::Status) -> Option<Message> + MaybeSend + 'static,
+ F: Fn(Event, event::Status, window::Id) -> Option<Message>
+ + MaybeSend
+ + 'static,
Message: 'static + MaybeSend,
{
Subscription::from_recipe(Runner {
@@ -298,8 +301,8 @@ where
use futures::future;
use futures::stream::StreamExt;
- events.filter_map(move |(event, status)| {
- future::ready(f(event, status))
+ events.filter_map(move |(event, status, window)| {
+ future::ready(f(event, status, window))
})
},
})
diff --git a/futures/src/subscription/tracker.rs b/futures/src/subscription/tracker.rs
index 277a446b..086b0f09 100644
--- a/futures/src/subscription/tracker.rs
+++ b/futures/src/subscription/tracker.rs
@@ -1,4 +1,5 @@
use crate::core::event::{self, Event};
+use crate::core::window;
use crate::subscription::{Hasher, Recipe};
use crate::{BoxFuture, MaybeSend};
@@ -23,7 +24,9 @@ pub struct Tracker {
#[derive(Debug)]
pub struct Execution {
_cancel: futures::channel::oneshot::Sender<()>,
- listener: Option<futures::channel::mpsc::Sender<(Event, event::Status)>>,
+ listener: Option<
+ futures::channel::mpsc::Sender<(Event, event::Status, window::Id)>,
+ >,
}
impl Tracker {
@@ -139,12 +142,19 @@ impl Tracker {
/// currently open.
///
/// [`Recipe::stream`]: crate::subscription::Recipe::stream
- pub fn broadcast(&mut self, event: Event, status: event::Status) {
+ pub fn broadcast(
+ &mut self,
+ event: Event,
+ status: event::Status,
+ window: window::Id,
+ ) {
self.subscriptions
.values_mut()
.filter_map(|connection| connection.listener.as_mut())
.for_each(|listener| {
- if let Err(error) = listener.try_send((event.clone(), status)) {
+ if let Err(error) =
+ listener.try_send((event.clone(), status, window))
+ {
log::warn!(
"Error sending event to subscription: {error:?}"
);