Skip to main content

RequestQueue

Struct RequestQueue 

Source
pub struct RequestQueue { /* private fields */ }
Expand description

Queue of SysEx requests and writes with at most one in flight.

Implementations§

Source§

impl RequestQueue

Source

pub fn new(timeout: Duration) -> Self

timeout: how long to wait for a reply before moving on (the official app uses 1 s).

Source

pub fn clear(&mut self)

Drop everything queued and in flight, and any sync in progress.

Source

pub fn start_sync(&mut self, reqs: Vec<Vec<u8>>)

Start a sync: replaces the queue with reqs, whose replies count towards progress.

Source

pub fn read(&mut self, bytes: Vec<u8>)

Queue a read. Ignored when the same request is already waiting.

Source

pub fn write(&mut self, bytes: Vec<u8>)

Queue a write (or any message that must keep its place after queued SysEx). Settings are rewritten whole on every change, so a queued settings write is replaced by the newer one.

Source

pub fn pop(&mut self) -> Option<Request>

The next message to send, if nothing is in flight. Pass it to sent once transmitted.

Source

pub fn sent(&mut self, r: Request, now: Instant)

Record that r went out at now; it is in flight until answered or timed out.

Source

pub fn on_message(&mut self, msg: &Msg) -> Option<Done>

Feed a complete incoming message. Returns the request it answers, if any.

Source

pub fn expire(&mut self, now: Instant) -> Option<Done>

Expire the in-flight request if it has waited longer than the timeout.

Source

pub fn progress(&self) -> (usize, usize)

(done, total) of the current sync; (0, 0) when none is running.

Source

pub fn in_flight(&self) -> Option<&Request>

Source

pub fn len(&self) -> usize

Messages waiting (not counting the one in flight).

Source

pub fn is_empty(&self) -> bool

Trait Implementations§

Source§

impl Debug for RequestQueue

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.