State of a timeout handle.
- active : Nat → HandleState
- paused : HandleState
- canceled : HandleState
Instances For
Equations
- System.TimeManager.instBEqHandleState.beq (System.TimeManager.HandleState.active a) (System.TimeManager.HandleState.active b) = (a == b)
- System.TimeManager.instBEqHandleState.beq System.TimeManager.HandleState.paused System.TimeManager.HandleState.paused = true
- System.TimeManager.instBEqHandleState.beq System.TimeManager.HandleState.canceled System.TimeManager.HandleState.canceled = true
- System.TimeManager.instBEqHandleState.beq x✝¹ x✝ = false
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
A timeout handle for a single connection. $$\text{Handle} = \text{IO.Ref}(\text{HandleState})$$
- state : IO.Ref HandleState
Instances For
The timeout manager. Periodically checks all registered handles. $$\text{Manager} = \{ \text{timeout} : \mathbb{N},\; \text{handles} : \text{IO.Ref}(\text{Array}(\text{Handle})) \}$$
- timeoutUs : Nat
Timeout duration in microseconds.
All registered handles.
- token : Std.CancellationToken
Cancellation token for stopping the background sweep.
Instances For
Initialize a new timeout manager with the given timeout (microseconds). Starts a background sweep task on a dedicated OS thread. $$\text{initialize} : \mathbb{N} \to \text{IO}(\text{Manager})$$
Equations
- One or more equations did not get rendered due to their size.
Instances For
Register a new connection with the manager. Returns a handle for managing its timeout. $$\text{register} : \text{Manager} \to \text{IO}(\text{Unit}) \to \text{IO}(\text{Handle})$$
Equations
- One or more equations did not get rendered due to their size.
Instances For
Reset the timeout for this handle (called on activity). $$\text{tickle} : \text{Handle} \to \text{Manager} \to \text{IO}(\text{Unit})$$
Equations
- h.tickle mgr = do let now ← liftM IO.monoNanosNow have deadline : Nat := now + mgr.timeoutUs * 1000 ST.Ref.set h.state (System.TimeManager.HandleState.active deadline)
Instances For
Cancel this handle's timeout. It will never fire. $$\text{cancel} : \text{Handle} \to \text{IO}(\text{Unit})$$
Equations
Instances For
Pause the timeout. The handle won't expire until resumed. $$\text{pause} : \text{Handle} \to \text{IO}(\text{Unit})$$
Equations
Instances For
Resume a paused handle with a fresh deadline. $$\text{resume} : \text{Handle} \to \text{Manager} \to \text{IO}(\text{Unit})$$
Equations
- h.resume mgr = do let now ← liftM IO.monoNanosNow have deadline : Nat := now + mgr.timeoutUs * 1000 ST.Ref.set h.state (System.TimeManager.HandleState.active deadline)