[][src]Trait yatp::Runner

pub trait Runner {
    type Task;
    fn handle(
        &mut self,
        spawn: &mut impl LocalSpawn<Task = Self::Task>,
        task: Self::Task
    ) -> bool; fn start(&mut self, _spawn: &mut impl LocalSpawn<Task = Self::Task>) { ... }
fn pause(&mut self, _spawn: &impl LocalSpawn<Task = Self::Task>) -> bool { ... }
fn resume(&mut self, _spawn: &impl LocalSpawn<Task = Self::Task>) { ... }
fn end(&mut self, _spawn: &impl LocalSpawn<Task = Self::Task>) { ... } }

In Yatp model, any pieces of logic aims to be executed in thread pool is called Task. There can be different definitions of Task. Some people may choose Future as Task, some may just want callbacks, or even Actor messages. But no matter what a Task is, there should be some role know how to execute it. The role is call Runner.

The life cycle of a Runner is:

  start
    |
    | <--- resume
    |        |
  handle -> pause
    |
   end

Generally users should use the provided future thread pool or callback thread pool instead. This is only for advance customization.

Associated Types

type Task

The task runner can handle.

Loading content...

Required methods

fn handle(
    &mut self,
    spawn: &mut impl LocalSpawn<Task = Self::Task>,
    task: Self::Task
) -> bool

Called when a task needs to be handled.

It's possible that a task can't be finished in a single execution, in which case feel free to spawn the task again and return false to indicate the task has not been finished yet.

Loading content...

Provided methods

fn start(&mut self, _spawn: &mut impl LocalSpawn<Task = Self::Task>)

Called when the runner is started.

It's guaranteed to be the first method to called before anything else.

fn pause(&mut self, _spawn: &impl LocalSpawn<Task = Self::Task>) -> bool

Called when the runner is put to sleep.

fn resume(&mut self, _spawn: &impl LocalSpawn<Task = Self::Task>)

Called when the runner is woken up.

fn end(&mut self, _spawn: &impl LocalSpawn<Task = Self::Task>)

Called when the runner is about to be destroyed.

It's guaranteed that no other method will be called after this method.

Loading content...

Implementors

Loading content...