[][src]Trait dynpool::System

pub trait System: Send + Sync + 'static {
    type Data;
    fn init(&self, index: usize) -> Self::Data;
fn work(&self, data: &mut Self::Data) -> Decision;
fn scale(&self) -> Scale; fn close(&self, Self::Data) { ... } }

Implementors of this trait provide a function to complete work and a function to determine the number of worker threads. This is the primary trait of the dynpool crate.

The user can implement this trait themselves, or use a builtin function such as fixed_scale for quick usage.

Associated Types

type Data

Per-worker data that pool should manage. Does not need to be Sync or Send.

Loading content...

Required methods

fn init(&self, index: usize) -> Self::Data

Called when a worker begins performing work, or is restarted. The returned data will be passed to future calls to work.

fn work(&self, data: &mut Self::Data) -> Decision

Do a unit of work, and return scheduling information.

fn scale(&self) -> Scale

How many active and inactive workers should the pool attempt to host? This function is checked frequently. It is also used to signal the graceful shutdown of the pool.

Dynpool will behave correctly even when the scale is highly inconsistent between calls. However, the LIFO ordering of thread indices may be momentarily violated in such cases, due to the lack of heavy locks on init and close.

Loading content...

Provided methods

fn close(&self, Self::Data)

After a worker decides to close, the associated data is passed to this function. Since the pool is highly parallel, and may be rapidly rescaling, a call to reinitialize the worker may sometimes occur before the call to close is complete.

Loading content...

Implementors

Loading content...