Implement window::frames subscription

... and use it in the `solar_system` example 🎉
This commit is contained in:
Héctor Ramón Jiménez 2023-01-12 04:35:41 +01:00
parent c649ec8cf7
commit 0b86c4a299
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
4 changed files with 43 additions and 4 deletions

View file

@ -59,8 +59,11 @@ pub fn events_with<Message>(
where
Message: 'static + MaybeSend,
{
#[derive(Hash)]
struct EventsWith;
Subscription::from_recipe(Runner {
id: f,
id: (EventsWith, f),
spawn: move |events| {
use futures::future;
use futures::stream::StreamExt;
@ -75,6 +78,28 @@ where
})
}
pub(crate) fn raw_events<Message>(
f: fn(Event, event::Status) -> Option<Message>,
) -> Subscription<Message>
where
Message: 'static + MaybeSend,
{
#[derive(Hash)]
struct RawEvents;
Subscription::from_recipe(Runner {
id: (RawEvents, f),
spawn: move |events| {
use futures::future;
use futures::stream::StreamExt;
events.filter_map(move |(event, status)| {
future::ready(f(event, status))
})
},
})
}
/// Returns a [`Subscription`] that will create and asynchronously run the
/// given [`Stream`].
///