Trait dynpool::System

source ·
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) { ... }
}
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

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

Required Methods

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

Do a unit of work, and return scheduling information.

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

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