[][src]Struct glommio::timer::TimerActionRepeat

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]

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]

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. If None, it stops.
  • tq the TaskQueueHandle 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]

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. If None, 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

impl Debug for TimerActionRepeat[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

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]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.