cosmic::app

Type Alias Task

Source
pub type Task<M> = Task<Action<M>>;

Aliased Type§

struct Task<M>(/* private fields */);

Implementations

Source§

impl<T> Task<T>

Source

pub fn none() -> Task<T>

Creates a Task that does nothing.

Source

pub fn done(value: T) -> Task<T>
where T: MaybeSend + 'static,

Creates a new Task that instantly produces the given value.

Source

pub fn perform<A>( future: impl Future<Output = A> + MaybeSend + 'static, f: impl Fn(A) -> T + MaybeSend + 'static, ) -> Task<T>
where T: MaybeSend + 'static, A: MaybeSend + 'static,

Creates a Task that runs the given Future to completion and maps its output with the given closure.

Source

pub fn run<A>( stream: impl Stream<Item = A> + MaybeSend + 'static, f: impl Fn(A) -> T + MaybeSend + 'static, ) -> Task<T>
where T: 'static,

Creates a Task that runs the given Stream to completion and maps each item with the given closure.

Source

pub fn batch(tasks: impl IntoIterator<Item = Task<T>>) -> Task<T>
where T: 'static,

Combines the given tasks and produces a single Task that will run all of them in parallel.

Source

pub fn map<O>(self, f: impl FnMut(T) -> O + MaybeSend + 'static) -> Task<O>
where T: MaybeSend + 'static, O: MaybeSend + 'static,

Maps the output of a Task with the given closure.

Source

pub fn then<O>( self, f: impl FnMut(T) -> Task<O> + MaybeSend + 'static, ) -> Task<O>
where T: MaybeSend + 'static, O: MaybeSend + 'static,

Performs a new Task for every output of the current Task using the given closure.

This is the monadic interface of Task—analogous to Future and Stream.

Source

pub fn chain(self, task: Task<T>) -> Task<T>
where T: 'static,

Chains a new Task to be performed once the current one finishes completely.

Source

pub fn collect(self) -> Task<Vec<T>>
where T: MaybeSend + 'static,

Creates a new Task that collects all the output of the current one into a Vec.

Source

pub fn discard<O>(self) -> Task<O>
where T: MaybeSend + 'static, O: MaybeSend + 'static,

Creates a new Task that discards the result of the current one.

Useful if you only care about the side effects of a Task.

Source

pub fn abortable(self) -> (Task<T>, Handle)
where T: 'static,

Creates a new Task that can be aborted with the returned Handle.

Source

pub fn future(future: impl Future<Output = T> + MaybeSend + 'static) -> Task<T>
where T: 'static,

Creates a new Task that runs the given Future and produces its output.

Source

pub fn stream(stream: impl Stream<Item = T> + MaybeSend + 'static) -> Task<T>
where T: 'static,

Creates a new Task that runs the given Stream and produces each of its items.

Trait Implementations

Source§

impl<T> From<()> for Task<T>

Source§

fn from(_value: ()) -> Task<T>

Converts to this type from the input type.