[−][src]Struct glommio::timer::TimerActionRepeat
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]
pub fn repeat_into<G, F>(
action_gen: G,
tq: TaskQueueHandle
) -> Result<TimerActionRepeat, QueueNotFoundError> where
G: Fn() -> F + 'static,
F: Future<Output = Option<Duration>> + 'static,
[src]
action_gen: G,
tq: TaskQueueHandle
) -> Result<TimerActionRepeat, QueueNotFoundError> 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::{LocalExecutorBuilder, Latency, Local, Shares}; use glommio::timer::TimerActionRepeat; 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::LocalExecutorBuilder; use glommio::timer::TimerActionRepeat; 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::LocalExecutorBuilder; use glommio::timer::TimerActionRepeat; 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::LocalExecutorBuilder; use glommio::timer::TimerActionRepeat; 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::LocalExecutorBuilder; use glommio::timer::TimerActionRepeat; 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 Send for TimerActionRepeat
impl Sync for TimerActionRepeat
impl Unpin for TimerActionRepeat
impl UnwindSafe for TimerActionRepeat
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
[src]
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,