Skip to main content

every

Function every 

Source
pub fn every<F>(duration: Duration, f: F) -> Cmd
where F: FnOnce(Instant) -> Message + Send + 'static,
Expand description

Command that ticks in sync with the system clock.

Unlike tick, this aligns with the system clock. For example, if you tick every second and the clock is at 12:34:20.5, the next tick will happen at 12:34:21.0 (in 0.5 seconds).

§Example

use bubbletea::{Cmd, every, Message};
use std::time::{Duration, Instant};

struct TickMsg(Instant);

fn tick_every_second() -> Cmd {
    every(Duration::from_secs(1), |t| Message::new(TickMsg(t)))
}