Skip to main content

Job

Trait Job 

Source
pub trait Job:
    Send
    + Sync
    + Sized {
    type Output: Send + Sync + 'static;
    type Error: Send + Sync + 'static + Into<Box<dyn Error + Send + Sync>>;

    // Required method
    fn run(
        self,
    ) -> impl Future<Output = Result<Self::Output, Self::Error>> + Send + Sync + 'static;

    // Provided methods
    fn then<F, Next>(self, next: F) -> Sequence<Self, Next, F>
       where F: FnOnce(Result<Self::Output, Self::Error>) -> Result<Next, Self::Error> + Send + Sync,
             Next: Job<Error = Self::Error> { ... }
    fn then_many<F, Next>(self, next: F) -> Sequence<Self, Vec<Next>, F>
       where F: FnOnce(Result<Self::Output, Self::Error>) -> Result<Vec<Next>, Self::Error> + Send + Sync,
             Next: Job<Error = Self::Error> { ... }
}
Expand description

A job that can be run asynchronously.

Required Associated Types§

Source

type Output: Send + Sync + 'static

Source

type Error: Send + Sync + 'static + Into<Box<dyn Error + Send + Sync>>

Job-specific error type. Must be convertible into a boxed error so WorkManager does not need to be generic over the error.

Required Methods§

Source

fn run( self, ) -> impl Future<Output = Result<Self::Output, Self::Error>> + Send + Sync + 'static

Runs the job and returns the result.

Provided Methods§

Source

fn then<F, Next>(self, next: F) -> Sequence<Self, Next, F>
where F: FnOnce(Result<Self::Output, Self::Error>) -> Result<Next, Self::Error> + Send + Sync, Next: Job<Error = Self::Error>,

Turns this job into a sequence where the next job depends on the output of this job. Does not execute anything until the entire sequence is run.

Source

fn then_many<F, Next>(self, next: F) -> Sequence<Self, Vec<Next>, F>
where F: FnOnce(Result<Self::Output, Self::Error>) -> Result<Vec<Next>, Self::Error> + Send + Sync, Next: Job<Error = Self::Error>,

Turns this job into a sequence of many jobs depending on the output of this job. Does not execute anything until the entire sequence is run.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<Prev, Next, F> Job for Sequence<Prev, Next, F>
where Prev: Job + 'static, F: FnOnce(Result<Prev::Output, Prev::Error>) -> Result<Next, Prev::Error> + Send + Sync + 'static, Next: Job<Error = Prev::Error> + 'static,

Source§

type Output = <Next as Job>::Output

Source§

type Error = <Prev as Job>::Error

Source§

impl<Prev, Next, F> Job for Sequence<Prev, Vec<Next>, F>
where Prev: Job + 'static, F: FnOnce(Result<Prev::Output, Prev::Error>) -> Result<Vec<Next>, Prev::Error> + Send + Sync + 'static, Next: Job<Error = Prev::Error> + 'static,

Source§

type Output = Vec<<Next as Job>::Output>

Source§

type Error = <Prev as Job>::Error