Copyright | Robert Fischer, 2016 |
---|---|
License | BSD3 |
Portability | POSIX |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
This provides a function, loop
, which loops on the Action
endlessly,
but no more than a Limit
number of times within a given TimePeriod
. This is useful
for preventing your server from accepting too many connections and exhausting your
available ports, or a file processor from exhausting your available file handles,
or a client that polls a message queue from abusing it through excessive requests,
or throttling any other number of processes that would be otherwise out of control.
- loop :: Action -> TimePeriod -> Limit -> ThreadHandle
- type Limit = Natural
- type TimePeriod = NominalDiffTime
- type Action = IO ()
- type ThreadHandle = IO ThreadId
Documentation
loop :: Action -> TimePeriod -> Limit -> ThreadHandle Source #
Takes an Action
that is processed repeatedly in a loop,
but no more than the Limit
number of times each TimePeriod
.
Use the ThreadHandle
to act on the processing thread.
Having a TimePeriod
of 0 or less will disable the timeout
functionality, and instead the loop will just yield
in between
each execution.
The number of times that the action will be executed within each period.
type TimePeriod = NominalDiffTime Source #
The length of time that defines each period.
type ThreadHandle = IO ThreadId Source #
A handle on the thread which is performing the loop