throttled-io-loop-0.1.0.2: Loop over an action but throttle it to a certain rate

CopyrightRobert Fischer, 2016
LicenseBSD3
PortabilityPOSIX
Safe HaskellTrustworthy
LanguageHaskell2010

Control.Concurrent.ThrottledLoop

Description

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.

Synopsis

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.

Having a Limit of 0 is equivalent to having a Limit of 1.

type Limit = Natural Source #

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 Action = IO () Source #

An action that can be performed.

type ThreadHandle = IO ThreadId Source #

A handle on the thread which is performing the loop