Enum interval_task::runner::Task

source ·
pub enum Task {
    TaskFn(Box<dyn FnTask + Send + Sync>),
    TaskFnMut(Box<dyn FnMutTask + Send + Sync>),
}

Variants§

§

TaskFn(Box<dyn FnTask + Send + Sync>)

§

TaskFnMut(Box<dyn FnMutTask + Send + Sync>)

Implementations§

source§

impl Task

source

pub fn new_fn_task(t: impl FnTask + Send + Sync + 'static) -> Task

source

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§

source§

impl TaskExt<()> for Task

source§

fn get_call<'a>(&'a mut self) -> Box<dyn FnMut() + Send + Sync + 'a>

source§

impl Send for Task

source§

impl Sync for Task

Auto Trait Implementations§

§

impl Freeze for Task

§

impl !RefUnwindSafe for Task

§

impl Unpin for Task

§

impl !UnwindSafe for Task

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.