use iced::Subscription;
use iced::time::Duration;
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
pub(crate) fn every(period: Duration) -> Subscription<()> {
iced::time::every(period).map(|_| ())
}
#[cfg(not(any(target_arch = "wasm32", feature = "tokio")))]
pub(crate) fn every(period: Duration) -> Subscription<()> {
use iced::futures::channel::mpsc;
Subscription::run_with(period, |period| {
let period = *period;
let (mut sender, receiver) = mpsc::channel(1);
std::thread::spawn(move || {
loop {
std::thread::sleep(period);
if sender
.try_send(())
.is_err_and(|error| error.is_disconnected())
{
break;
}
}
});
receiver
})
}