Struct glommio::timer::TimerActionRepeat [−][src]
pub struct TimerActionRepeat { /* fields omitted */ }
The TimerActionRepeat struct provides an ergonomic way to fire a repeated
action at specified intervals, without having to fire new
TimerActionOnce
events
Implementations
impl TimerActionRepeat
[src]
impl TimerActionRepeat
[src]pub fn repeat_into<G, F>(
action_gen: G,
tq: TaskQueueHandle
) -> Result<TimerActionRepeat, ()> where
G: Fn() -> F + 'static,
F: Future<Output = Option<Duration>> + 'static,
[src]
action_gen: G,
tq: TaskQueueHandle
) -> Result<TimerActionRepeat, ()> where
G: Fn() -> F + 'static,
F: Future<Output = Option<Duration>> + 'static,
Creates a TimerActionRepeat
that will execute the associated future
repeatedly in a specific Task Queue until returns None
Arguments
action_gen
a Future to be executed repeatedly. The Future’s return value must be Option. If Some
, It will execute again after Duration elapses. IfNone
, it stops.tq
theTaskQueueHandle
for the TaskQueue we want.
Examples
use glommio::{timer::TimerActionRepeat, Latency, Local, LocalExecutorBuilder, Shares}; use std::time::Duration; let handle = LocalExecutorBuilder::new() .spawn(|| async move { let tq = Local::create_task_queue(Shares::default(), Latency::NotImportant, "test"); let action = TimerActionRepeat::repeat_into( || async move { println!("Execute this!"); Some(Duration::from_millis(100)) }, tq, ) .unwrap(); action.join().await; // this never returns }) .unwrap(); handle.join().unwrap();
pub fn repeat<G, F>(action_gen: G) -> TimerActionRepeat where
G: Fn() -> F + 'static,
F: Future<Output = Option<Duration>> + 'static,
[src]
G: Fn() -> F + 'static,
F: Future<Output = Option<Duration>> + 'static,
Creates a TimerActionRepeat
that will execute the associated future
repeatedly until it returns None
Arguments
action_gen
a Future to be executed repeatedly. The Future’s return value must be Option. If Some
, It will execute again after Duration elapses. IfNone
, it stops.
Examples
use glommio::{timer::TimerActionRepeat, LocalExecutorBuilder}; use std::time::Duration; let handle = LocalExecutorBuilder::new() .spawn(|| async move { let action = TimerActionRepeat::repeat(|| async move { println!("Execute this!"); Some(Duration::from_millis(100)) }); action.join().await; // this never returns }) .unwrap(); handle.join().unwrap();
pub async fn cancel(self)
[src]
Cancel an existing TimerActionRepeat
and waits for it to return
If you want to cancel the timer but doesn’t want to .await on it,
prefer destroy
.
Examples
use glommio::{timer::TimerActionRepeat, LocalExecutorBuilder}; use std::time::Duration; let handle = LocalExecutorBuilder::new() .spawn(|| async move { let action = TimerActionRepeat::repeat(|| async move { Some(Duration::from_millis(100)) }); action.cancel().await; }) .unwrap(); handle.join().unwrap();
pub fn destroy(&self)
[src]
Cancel an existing TimerActionRepeat
, without waiting for it to
return
This is a non-async version of cancel
. It will remove the timer if
it hasn’t fired already and destroy the TimerActionRepeat
releasing
the resources associated with it, but without blocking the current
task. It is still possible to join
the task if needed.
Examples
use glommio::{timer::TimerActionRepeat, LocalExecutorBuilder}; use std::time::Duration; let handle = LocalExecutorBuilder::new() .spawn(|| async move { let action = TimerActionRepeat::repeat(|| async move { Some(Duration::from_millis(100)) }); action.destroy(); let v = action.join().await; assert!(v.is_none()) }) .unwrap(); handle.join().unwrap();
pub async fn join(self) -> Option<()>
[src]
Waits for a TimerActionRepeat
to return
Returns an Option
with value None if the task was canceled and
Some(()) if the action finished successfuly
Examples
use glommio::{timer::TimerActionRepeat, LocalExecutorBuilder}; use std::time::Duration; let handle = LocalExecutorBuilder::new() .spawn(|| async move { let action = TimerActionRepeat::repeat(|| async move { None }); let v = action.join().await; assert!(v.is_some()) }) .unwrap(); handle.join().unwrap();
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for TimerActionRepeat
impl !RefUnwindSafe for TimerActionRepeat
impl !Send for TimerActionRepeat
impl !Send for TimerActionRepeat
impl !Sync for TimerActionRepeat
impl !Sync for TimerActionRepeat
impl Unpin for TimerActionRepeat
impl Unpin for TimerActionRepeat
impl !UnwindSafe for TimerActionRepeat
impl !UnwindSafe for TimerActionRepeat