System

Trait System 

Source
pub trait System:
    Send
    + Sync
    + 'static {
    type Data;

    // Required methods
    fn init(&self, index: usize) -> Self::Data;
    fn work(&self, data: &mut Self::Data) -> Decision;
    fn scale(&self) -> Scale;

    // Provided method
    fn close(&self, _: Self::Data) { ... }
}
Expand description

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.

Required Associated Types§

Source

type Data

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

Required Methods§

Source

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.

Source

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

Do a unit of work, and return scheduling information.

Source

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.

Provided Methods§

Source

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.

Implementors§