pub struct RequestQueue { /* private fields */ }Expand description
Queue of SysEx requests and writes with at most one in flight.
Implementations§
Source§impl RequestQueue
impl RequestQueue
Sourcepub fn new(timeout: Duration) -> Self
pub fn new(timeout: Duration) -> Self
timeout: how long to wait for a reply before moving on (the official app uses 1 s).
Sourcepub fn start_sync(&mut self, reqs: Vec<Vec<u8>>)
pub fn start_sync(&mut self, reqs: Vec<Vec<u8>>)
Start a sync: replaces the queue with reqs, whose replies count towards progress.
Sourcepub fn read(&mut self, bytes: Vec<u8>)
pub fn read(&mut self, bytes: Vec<u8>)
Queue a read. Ignored when the same request is already waiting.
Sourcepub fn write(&mut self, bytes: Vec<u8>)
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.
Sourcepub fn pop(&mut self) -> Option<Request>
pub fn pop(&mut self) -> Option<Request>
The next message to send, if nothing is in flight. Pass it to sent once transmitted.
Sourcepub fn sent(&mut self, r: Request, now: Instant)
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.
Sourcepub fn on_message(&mut self, msg: &Msg) -> Option<Done>
pub fn on_message(&mut self, msg: &Msg) -> Option<Done>
Feed a complete incoming message. Returns the request it answers, if any.
Sourcepub fn expire(&mut self, now: Instant) -> Option<Done>
pub fn expire(&mut self, now: Instant) -> Option<Done>
Expire the in-flight request if it has waited longer than the timeout.
Sourcepub fn progress(&self) -> (usize, usize)
pub fn progress(&self) -> (usize, usize)
(done, total) of the current sync; (0, 0) when none is running.