Task

Trait Task 

Source
pub trait Task<T>: Future<Output = T> {
    // Required methods
    fn is_finished(&self) -> bool;
    fn cancel(self);
}
Expand description

The Task trait represents an asynchronous task.

Task is an abstraction over a specific task in some async runtime like tokio::task::JoinHandle<T>.

§Examples

use node_flow::context::Task;
use std::future::Future;

struct DummyTask;

impl Future for DummyTask {
    type Output = u8;
    fn poll(
        self: std::pin::Pin<&mut Self>,
        _: &mut std::task::Context<'_>
    ) -> std::task::Poll<Self::Output> {
        std::task::Poll::Ready(5)
    }
}

impl Task<u8> for DummyTask {
    fn is_finished(&self) -> bool { true }
    fn cancel(self) {}
}

Required Methods§

Source

fn is_finished(&self) -> bool

Returns true if the task has finished.

Source

fn cancel(self)

Cancels the task if it is still running.

The implementation should attempt to stop or drop any ongoing work. Be aware that tasks spawned using SpawnSync::spawn_blocking may or may not be canceled, because they are not async (it all depends on the implementor).

Implementors§