Skip to main content

DeadlineSource

Trait DeadlineSource 

Source
pub trait DeadlineSource {
    type Output;

    // Required methods
    fn expected_duration(&self) -> Duration;
    fn action(
        self: Rc<Self>,
    ) -> Pin<Box<dyn Future<Output = Self::Output> + 'static>>;
    fn total_units(&self) -> u64;
    fn processed_units(&self) -> u64;
}
Expand description

Items going into the DeadlineQueue must implement this trait.

It allows the DeadlineQueue to understand the progress and expectations of processing this item

Required Associated Types§

Source

type Output

What type is returned by the action method

Required Methods§

Source

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.

Source

fn action( 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())
}
Source

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.

Source

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.

Trait Implementations§

Source§

impl<T> Debug for dyn DeadlineSource<Output = T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§