[−][src]Trait glommio::controllers::DeadlineSource
Items going into the DeadlineQueue
must implement this trait.
It allows the DeadlineQueue
to understand the progress and expectations
of processing this item
Associated Types
Loading content...Required methods
fn expected_duration(&self) -> Duration
Returns a Duration
indicating when we would like this operation to complete.
It is calculated from the point of Queueing, not from the point in which the operation starts.
fn action(
self: Rc<Self>
) -> Pin<Box<dyn Future<Output = Self::Output> + 'static>>
self: Rc<Self>
) -> Pin<Box<dyn Future<Output = Self::Output> + 'static>>
The action to execute. Usually your struct will implement an async function that you want to see completed at a particular deadline, and then the implementation of this would be:
fn action(&self) -> Pin<Box<dyn Future<Output = io::Result<Duration>> + 'static>> { Box::pin(self.my_action()) }
fn total_units(&self) -> u64
The total amount of units to be processed.
This could be anything you want:
- If you are flushing a file, this could indicate the size in bytes of the buffer
- If you are scanning an array, this could be the number of elements.
As long as this quantity is consistent with processed_units
the controllers should work.
This need not be static. On the contrary: as you are filling a new buffer you can already add it to the queue and increase its total units as the buffer is written to. This can lead to smoother operation as opposed to just adding a lot of units at once.
fn processed_units(&self) -> u64
The amount of units that were already processed.
The units should match the quantities specified in total_units
.
The more often the system is made aware of processed units, the smoother the
controller will be.
For example, you can buffer all updates and just inform that processed_units == total_units at the end of the process, but then the controller would be a step function.