Task

Struct Task 

Source
pub struct Task<R: Runtime> {
    pub schedule: Box<dyn Schedule + Send>,
    pub run: Box<RunTaskFn<R>>,
}
Expand description

Task to be scheduled

§Fields

  • schedule: a Schedule trait object
  • run: function to create a new task in specific runtime R

Fields§

§schedule: Box<dyn Schedule + Send>§run: Box<RunTaskFn<R>>

Implementations§

Source§

impl Task<AsyncStd>

Source

pub fn async_std<S, F, Fut>(schedule: S, task: F) -> Self
where S: IntoSchedule, S::Output: Send + 'static, F: Fn() -> Fut + Send + 'static, Fut: Future<Output = ()> + Send + 'static,

Create a new task that will be executed with async_std.

§Example
let task = Task::async_std(now(), || async {
   println!("Hello, world!");
});
Source§

impl Task<Tokio>

Source

pub fn tokio<S, F, Fut>(schedule: S, task: F) -> Self
where S: IntoSchedule, S::Output: Send + 'static, F: Fn() -> Fut + Send + 'static, Fut: Future<Output = ()> + Send + 'static,

Create a new task that will be executed with tokio.

§Example
let task = Task::tokio(now(), || async {
  println!("Hello, world!");
});
Source§

impl Task<Thread>

Source

pub fn thread<S, F>(schedule: S, task: F) -> Self
where S: IntoSchedule, S::Output: Send + 'static, F: Fn() + Send + 'static + Clone,

Source§

impl Task<Promise>

Source

pub fn promise<S, F, Fut>(schedule: S, task: F) -> Self
where S: IntoSchedule, S::Output: Send + 'static, F: Fn() -> Fut + Send + 'static, Fut: Future<Output = ()> + 'static,

Create a new task that will be executed with promise.

§Example
async fn some_task() {

}

let task = Task::promise(now(), some_task);
Source§

impl Task<Local>

Source

pub fn local<S, F>(schedule: S, task: F) -> Self
where S: IntoSchedule, S::Output: Send + 'static, F: Fn() + Send + 'static + Clone,

Source§

impl<R: Runtime> Task<R>

Source

pub fn new<S, F, A>(schedule: S, run: F) -> Self
where S: IntoSchedule, F: IntoRunTaskFn<R, A>,

Create a new task.

The run function could have the following signature:

Fn(<&mut Runtime>?, ..Args)

the Args could be any type that implements TaskRunArg.

For now, these types are supported:

  • TaskRun : information about this run.
  • TaskUid : the task unique identifier.
  • Dtu : the time when this task is scheduled to run.

For example, you can call this function like this:

let task = Task::<Local>::new(now(), |time: Dtu, id: TaskUid| {
   println!("Time: {time}, Uid: {id}");
});
Source§

impl<R: AsyncRuntime> Task<R>

Source

pub fn new_async<S, F, A, Fut>(schedule: S, run: F) -> Self
where S: IntoSchedule, F: IntoRunTaskFn<R, Async<A, Fut>>,

This is basically the same as Task::new but with more hint for compiler that this is an async function.

Trait Implementations§

Source§

impl<R: Runtime> Debug for Task<R>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<R> Freeze for Task<R>

§

impl<R> !RefUnwindSafe for Task<R>

§

impl<R> Send for Task<R>

§

impl<R> !Sync for Task<R>

§

impl<R> Unpin for Task<R>

§

impl<R> !UnwindSafe for Task<R>

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>,

Source§

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>,

Source§

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.