Enum interval_task::runner::Task
source · pub enum Task {
TaskFn(Box<dyn FnTask + Send + Sync>),
TaskFnMut(Box<dyn FnMutTask + Send + Sync>),
}Variants§
Implementations§
source§impl Task
impl Task
pub fn new_fn_task(t: impl FnTask + Send + Sync + 'static) -> Task
sourcepub fn new_fn_mut_task(t: impl FnMutTask + Send + Sync + 'static) -> Task
pub fn new_fn_mut_task(t: impl FnMutTask + Send + Sync + 'static) -> Task
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
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();
}Trait Implementations§
Auto Trait Implementations§
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