Struct interval_task::runner::Runner
source · pub struct Runner<T> { /* private fields */ }Implementations§
source§impl<T> Runner<T>
impl<T> Runner<T>
pub fn new(interval: Duration) -> Runner<T>
sourcepub fn set_task(&mut self, t: T)
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();
}pub fn get_thread_ref(&self) -> &Thread
Trait Implementations§
source§impl ExternalRunnerExt for Runner<Task>
impl ExternalRunnerExt for Runner<Task>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more