| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Ecluse.Core.Deadline
Contents
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
- data Deadlines
- newDeadlines :: IO Deadlines
- sweepTick :: Deadlines -> IO ()
- type Check = Word64 -> IO (Maybe SomeException)
- withDeadline :: Deadlines -> Check -> IO a -> IO a
- withEndableDeadline :: Deadlines -> Check -> (IO () -> IO a) -> IO a
- withDeadlineFlag :: Deadlines -> Int -> (TVar Bool -> IO a) -> IO a
- timeout :: Deadlines -> Int -> IO a -> IO (Maybe a)
- inspectionDeadline :: Deadlines -> e -> IO (Either e a) -> IO (Either e a)
The sweeper
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.