pub struct Driver<T> { /* private fields */ }tokio only.Expand description
Pumps a session over a transport.
One step flushes everything the session wants to send, then waits for whichever
comes first: an inbound frame, the session’s next deadline, or the keep-alive
interval. The application keeps the loop, and with it the freedom to do anything else
between steps.
Implementations§
Source§impl<T: TextTransport> Driver<T>
impl<T: TextTransport> Driver<T>
Sourcepub fn with_clock(self, now: fn() -> Timestamp) -> Self
pub fn with_clock(self, now: fn() -> Timestamp) -> Self
Use a different clock — a virtual one, in a test.
Sourcepub fn with_ping_interval(self, interval: Duration) -> Self
pub fn with_ping_interval(self, interval: Duration) -> Self
Send pings at a different interval. S2 Connect allows up to sixty seconds.
Sourcepub fn transport_mut(&mut self) -> &mut T
pub fn transport_mut(&mut self) -> &mut T
The transport, for a caller that wants to close it itself.
Sourcepub async fn step<S: Session>(&mut self, session: &mut S) -> Result<(), Error>
pub async fn step<S: Session>(&mut self, session: &mut S) -> Result<(), Error>
Run one step of a session, whichever role it is.
Flush, wait for the first of {a frame, the session’s deadline, the keep-alive interval}, feed the result back in, flush again. Everything that decides anything is in the session; this function decides only what to wait on.
Sourcepub async fn run<S, F>(
&mut self,
session: &mut S,
on_event: F,
) -> Result<(), Error>
pub async fn run<S, F>( &mut self, session: &mut S, on_event: F, ) -> Result<(), Error>
Run a session to completion: steps until it closes.
The application still sees every event, through the callback, but no longer owns
the loop. For anything that wants to do other work between steps, use
Self::step.