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

pub struct TimerActionRepeat { /* fields omitted */ }
Expand description

The TimerActionRepeat struct provides an ergonomic way to fire a repeated action at specified intervals, without having to fire new TimerActionOnce events

Implementations

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::{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();

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::{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();

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();

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();

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

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more