Trait yatp::pool::Runner[][src]

pub trait Runner {
    type TaskCell;
    fn handle(
        &mut self,
        local: &mut Local<Self::TaskCell>,
        task_cell: Self::TaskCell
    ) -> bool; fn start(&mut self, _local: &mut Local<Self::TaskCell>) { ... }
fn pause(&mut self, _local: &mut Local<Self::TaskCell>) -> bool { ... }
fn resume(&mut self, _local: &mut Local<Self::TaskCell>) { ... }
fn end(&mut self, _local: &mut Local<Self::TaskCell>) { ... } }

In the model of yatp, any piece of logic aiming to be executed in a 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 TaskCell[src]

The local spawn that can be accepted to spawn tasks.

Loading content...

Required methods

fn handle(
    &mut self,
    local: &mut Local<Self::TaskCell>,
    task_cell: Self::TaskCell
) -> bool
[src]

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, _local: &mut Local<Self::TaskCell>)[src]

Called when the runner is started.

It’s guaranteed to be the first method to call before anything else.

fn pause(&mut self, _local: &mut Local<Self::TaskCell>) -> bool[src]

Called when the runner is put to sleep.

fn resume(&mut self, _local: &mut Local<Self::TaskCell>)[src]

Called when the runner is woken up.

fn end(&mut self, _local: &mut Local<Self::TaskCell>)[src]

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

impl Runner for yatp::task::callback::Runner[src]

type TaskCell = TaskCell

impl Runner for yatp::task::future::Runner[src]

type TaskCell = TaskCell

impl<R, T> Runner for MultilevelRunner<R> where
    R: Runner<TaskCell = T>,
    T: TaskCell
[src]

type TaskCell = T

Loading content...