pub trait Dependencies: Debug + Sized {
type Instant: Instant<Duration = Self::Duration>;
type Duration: Duration;
// Required methods
fn register_timer(
&self,
time: Self::Instant,
f: impl FnOnce(&mut TcpState<Self>, TimerRegisteredBy) + Send + Sync + 'static,
);
fn current_time(&self) -> Self::Instant;
fn fork(&self) -> Self;
}
Expand description
A collection of methods that allow the TCP state to interact with the external system.
Required Associated Types§
Required Methods§
sourcefn register_timer(
&self,
time: Self::Instant,
f: impl FnOnce(&mut TcpState<Self>, TimerRegisteredBy) + Send + Sync + 'static,
)
fn register_timer( &self, time: Self::Instant, f: impl FnOnce(&mut TcpState<Self>, TimerRegisteredBy) + Send + Sync + 'static, )
Register a timer. The callback will be run on the parent state. The callback can
use the TimerRegisteredBy
argument to know whether the timer was registered by the
parent state or one of its child states.
If a child state has not yet been accept()ed, it will be owned by a parent state. When a
child state registers a timer, the timer’s callback will run on the parent state and the
callback will be given the TimerRegisteredBy::Child
argument so that the callback can
delegate accordingly.
sourcefn current_time(&self) -> Self::Instant
fn current_time(&self) -> Self::Instant
Get the current time.
sourcefn fork(&self) -> Self
fn fork(&self) -> Self
Create a new Dependencies
for use by a child state. When a timer is registered by the
child state using this new object, the timer’s callback will be run on the parent’s state
with the TimerRegisteredBy::Child
argument so that the parent knows to run the callback on
one of its child states.
When a child state has been accept()ed, it will no longer be owned by the parent state and
the parent state has no way to access this child state. The child state’s Dependencies
should be updated during the finalize
call (on the
AcceptedTcpState
returned from accept
) to run callbacks directly
on this state instead, and the callbacks should be given TimerRegisteredBy::Parent
(the
child state has effectively become a parent state). This Dependencies
object should also
make sure that all existing timers from before the state was accept()ed are also updated to
run callbacks directly on the state.