time-manager-0.5.2: Scalable timer
Safe HaskellNone
LanguageHaskell2010

System.TimeManager

Description

Timeout manager. Since v0.3.0, timeout manager is a wrapper of GHC System TimerManager, except on Windows, where it has a timer of its own: the one in GHC.Event.Windows belongs to WinIO and never runs under the I/O manager which is still the default there.

Some caveats of using this package:

  • Only works for GHC
  • Only works with a threaded runtime
  • Users of older versions should check the current semantics.
  • Using 32-bit systems means the max timeout is maxBound :: Int (2147483647) microseconds, which is less than 36 minutes.
  • Using the same Handle in different threads might cause issues in some edge cases. (i.e. using cancel/pause in one thread, and resume in another)
Synopsis

Types

data Manager Source #

A timeout manager

defaultManager :: Manager Source #

A manager whose timeout value is 0 (no callbacks are fired).

type TimeoutAction = IO () Source #

An action (callback) to be performed on timeout.

data Handle Source #

A handle used by a timeout manager.

Manager

initialize :: Int -> IO Manager Source #

Creating timeout manager with a timeout value in microseconds.

Setting the timeout to zero or lower (<= 0) will produce a defaultManager.

stopManager :: Manager -> IO () Source #

Deprecated: This function does nothing since version 0.3.0

Obsoleted since version 0.3.0 Is now equivalent to pure ().

killManager :: Manager -> IO () Source #

Deprecated: This function does nothing since version 0.3.0

Obsoleted since version 0.3.0 Is now equivalent to pure ().

withManager Source #

Arguments

:: Int

timeout in microseconds

-> (Manager -> IO a) 
-> IO a 

Call the inner function with a timeout manager.

withManager' Source #

Arguments

:: Int

timeout in microseconds

-> (Manager -> IO a) 
-> IO a 

Deprecated: This function is the same as withManager since version 0.3.0

Call the inner function with a timeout manager. This is identical to withManager.

Registering a timeout action

withHandle :: Manager -> TimeoutAction -> (Handle -> IO a) -> IO a Source #

Registering a timeout action and unregister its handle when the body action is finished.

withHandleKillThread :: Manager -> TimeoutAction -> (Handle -> IO ()) -> IO () Source #

Registering a timeout action of killing this thread and unregister its handle when the body action is killed or finished.

Control timeout

tickle :: Handle -> IO () Source #

Extending the timeout.

To keep frequent callers cheap, the renewal is rate-limited: it is skipped unless at least a quarter of the timeout (capped at one second) has passed since the timeout was last registered or updated.

Careful: this does NOT reactivate an already paused Handle!

pause :: Handle -> IO () Source #

Pauses the timeout so you can resume it later. Does not stop it entirely. Use cancel if you want to make sure the action will not be resumed.

To resume a timeout with the same Handle, resume MUST be called. Don't call tickle for resumption.

resume :: Handle -> IO () Source #

Resuming the timeout.

Works like tickle if the Handle wasn't paused or canceled.

cancel :: Handle -> IO () Source #

Unregistering the timeout.

The timeout can not be resumed. To "resume" the timeout, you need to register again.

Low level

register :: Manager -> TimeoutAction -> IO Handle Source #

Registering a timeout action.

registerKillThread :: Manager -> TimeoutAction -> IO Handle Source #

Registering a timeout action of killing this thread. TimeoutThread is thrown to the thread which called this function on timeout. Catch TimeoutThread if you don't want to leak the asynchronous exception to GHC RTS.

Exceptions

data TimeoutThread Source #

The asynchronous exception thrown if a thread is registered via registerKillThread.

Constructors

TimeoutThread