Enum interval_task::runner::TaskWithHandle
source · pub enum TaskWithHandle {
TaskFnHanle(Box<dyn FnTaskWithHandle + Send + Sync>),
TaskFnMutHanle(Box<dyn FnMutTaskWithHandle + Send + Sync>),
}Variants§
TaskFnHanle(Box<dyn FnTaskWithHandle + Send + Sync>)
TaskFnMutHanle(Box<dyn FnMutTaskWithHandle + Send + Sync>)
Implementations§
source§impl TaskWithHandle
impl TaskWithHandle
pub fn new_fn_task( t: impl FnTaskWithHandle + Send + Sync + 'static, ) -> TaskWithHandle
sourcepub fn new_fn_mut_task(
t: impl FnMutTaskWithHandle + Send + Sync + 'static,
) -> TaskWithHandle
pub fn new_fn_mut_task( t: impl FnMutTaskWithHandle + Send + Sync + 'static, ) -> TaskWithHandle
Examples found in repository?
examples/runner.rs (lines 56-59)
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 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();
}Trait Implementations§
source§impl TaskExt<bool> for TaskWithHandle
impl TaskExt<bool> for TaskWithHandle
impl Send for TaskWithHandle
impl Sync for TaskWithHandle
Auto Trait Implementations§
impl Freeze for TaskWithHandle
impl !RefUnwindSafe for TaskWithHandle
impl Unpin for TaskWithHandle
impl !UnwindSafe for TaskWithHandle
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