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
Required Methods
sourcefn init(&self, index: usize) -> Self::Data
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
.
sourcefn work(&self, data: &mut Self::Data) -> Decision
fn work(&self, data: &mut Self::Data) -> Decision
Do a unit of work, and return scheduling information.
sourcefn scale(&self) -> Scale
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
.