epoll-0.1: src/System/Linux/Epoll.hs
-- |
-- Module : System.Linux.Epoll
-- Copyright : (c) 2009 Toralf Wittner
-- License : LGPL
-- Maintainer : toralf.wittner@gmail.com
-- Stability : experimental
-- Portability : non-portable
module System.Linux.Epoll (
module System.Linux.Epoll.Base,
dispatchLoop,
defaultDispatchLoop
) where
import Data.Maybe
import Control.Monad
import System.Linux.Epoll.Base
-- | Repeatedly waits for epoll events and invokes the given callback function
-- with each event occured.
dispatchLoop :: Duration -> (Event a -> IO ()) -> Device -> IO ()
dispatchLoop dur f dev = forever $ wait dur dev >>= mapM_ (\e -> f e)
-- | Like 'dispatchLoop' but uses a default 'Duration' of 500ms.
defaultDispatchLoop :: (Event a -> IO ()) -> Device -> IO ()
defaultDispatchLoop = dispatchLoop (fromJust $ toDuration 500)