Skip to main content

freya_core/
rendering_ticker.rs

1use crate::prelude::consume_root_context;
2
3pub type RenderingTickerSender = async_watch::Sender<()>;
4
5/// Receives frame notifications.
6#[derive(Clone)]
7pub struct RenderingTicker {
8    rx: async_watch::Receiver<()>,
9}
10
11impl RenderingTicker {
12    pub fn get() -> Self {
13        consume_root_context()
14    }
15
16    pub fn new() -> (RenderingTickerSender, Self) {
17        let (tx, rx) = async_watch::channel(());
18        (tx, Self { rx })
19    }
20
21    /// Wait until the next frame should be processed.
22    pub async fn tick(&mut self) {
23        self.rx.changed().await.ok();
24    }
25}