Struct interval_task::runner::Runner

source ·
pub struct Runner<T> { /* private fields */ }

Implementations§

source§

impl<T> Runner<T>

source

pub fn new(interval: Duration) -> Runner<T>

source

pub fn set_task(&mut self, t: T)

Examples found in repository?
examples/runner.rs (line 28)
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
fn external_close_example() {
    use interval_task::runner::{self, ExternalRunnerExt, FnMutTask, Task};

    struct TestTask(u32, async_channel::Sender<u8>);
    impl FnMutTask for TestTask {
        fn call_mut(&mut self) {
            if self.0 == 119 {
                self.1.send_blocking(0).unwrap();
            } else {
                self.0 += 1
            }
        }
    }

    let mut runner = runner::new_external_close_runner(Duration::from_micros(1_000_000 / 120));
    let (s, r) = async_channel::bounded(1);
    runner.set_task(Task::new_fn_mut_task(TestTask(0, s)));
    runner.start().unwrap();
    let start = Instant::now();
    r.recv_blocking().unwrap();
    println!("Elapsed: {:?}", start.elapsed());
    runner.close().unwrap();
}

fn internal_close_example() {
    use interval_task::runner::{self, InternalRunnerExt, TaskWithHandle};
    use std::time::{Duration, Instant};

    struct RunnerTask(u32, Instant);
    impl runner::FnMutTaskWithHandle for RunnerTask {
        fn call_mut(&mut self) -> bool {
            if self.0 == 119 {
                println!("{}", self.1.elapsed().as_secs_f64());
                true
            } else {
                if self.0 == 0 {
                    self.1 = Instant::now();
                }
                self.0 += 1;
                false
            }
        }
    }
    let mut runner = runner::new_internal_close_runner(Duration::from_micros(1_000_000 / 120));
    runner.set_task(TaskWithHandle::new_fn_mut_task(RunnerTask(
        0,
        Instant::now(),
    )));
    runner.start().unwrap();
    runner.join().unwrap();
}
source

pub fn get_thread_ref(&self) -> &Thread

Trait Implementations§

source§

impl ExternalRunnerExt for Runner<Task>

source§

fn close(self) -> Result<(), &'static str>

!!! DO NOT USE THIS IF true WILL BE RETURNED FROM Task, INSTEAD, USE join(). Send signal to runner, wait for response and join thread. Gets dropped after call

source§

fn start(&mut self) -> Result<(), &str>

source§

impl InternalRunnerExt for Runner<TaskWithHandle>

source§

fn join(self) -> Result<(), &'static str>

object moved and gets dropped after call

source§

fn start(&mut self) -> Result<(), &'static str>

Auto Trait Implementations§

§

impl<T> Freeze for Runner<T>
where T: Freeze,

§

impl<T> !RefUnwindSafe for Runner<T>

§

impl<T> Send for Runner<T>
where T: Send,

§

impl<T> Sync for Runner<T>
where T: Sync,

§

impl<T> !Unpin for Runner<T>

§

impl<T> !UnwindSafe for Runner<T>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.