ecluse:ecluse-core
Safe HaskellNone
LanguageGHC2021

Ecluse.Core.Deadline

Description

Deadlines that one sweeper thread checks every 100 ms, so arming one never waits on another thread. GHC's timers share one process-wide queue, and every arm and disarm edits it in turn. Here arming adds to a list owned by the arming thread's capability, and a deadline fires about one tick late. A due check is thrown from a forked thread, as timeout does, so a disarm can stop a throw still in flight. A flag scope raises a TVar instead, for a transaction that waits.

Synopsis

The sweeper

data Deadlines Source #

The process's armed checks, one list for each capability.

newDeadlines :: IO Deadlines Source #

One list for each capability the process runs now. Create it once the capability count is final.

sweepTick :: Deadlines -> IO () Source #

Wait one tick, then raise every due check. The composition root repeats it under supervision.

Armed scopes

type Check = Word64 -> IO (Maybe SomeException) Source #

Asked at each sweep with the monotonic time in nanoseconds. A Just is raised in the armed thread, and ends the check.

withDeadline :: Deadlines -> Check -> IO a -> IO a Source #

Run an action under a check the sweeper asks every tick. A failure it returns is raised in this thread while the action runs, and never after it ends.

withEndableDeadline :: Deadlines -> Check -> (IO () -> IO a) -> IO a Source #

withDeadline whose action can end the check early. Once the end returns, nothing the check raised lands.

withDeadlineFlag :: Deadlines -> Int -> (TVar Bool -> IO a) -> IO a Source #

Run an action with a flag the first sweep after the microseconds raises, so a transaction can wait for the deadline without a GHC timer. A bound of zero or less starts raised and needs no sweep.

timeout :: Deadlines -> Int -> IO a -> IO (Maybe a) Source #

timeout on the sweeper: Nothing once the action outlives the microseconds, about a tick late. A negative bound never fires, and zero fires at once.

inspectionDeadline :: Deadlines -> e -> IO (Either e a) -> IO (Either e a) Source #

Return the refusal once an archive or metadata inspection outlives the request timeout, on the sweeper.