Skip to content

Instantly share code, notes, and snippets.

@aycanirican
Created July 14, 2010 14:18
Show Gist options
  • Save aycanirican/475462 to your computer and use it in GitHub Desktop.
Save aycanirican/475462 to your computer and use it in GitHub Desktop.
-- | throw a timeout exception to the handling thread -- it'll clean up
-- everything
timerCallback :: EvLoopPtr -- ^ loop obj
-> EvTimerPtr -- ^ timer obj
-> IORef CTime -- ^ when to timeout?
-> MVar ThreadId -- ^ thread to kill
-> TimerCallback
timerCallback loop tmr ioref tmv _ _ _ = do
debug "Backend.timerCallback: entered"
now <- getCurrentDateTime
whenToDie <- readIORef ioref
if whenToDie < now
then do
debug "Backend.timerCallback: killing thread"
tid <- readMVar tmv
throwTo tid TimeoutException
else do -- re-arm the timer
-- fixme: should set repeat here, have to wait for an hlibev patch to
-- do it
let newtval = fromRational . toRational $ (whenToDie - now)
evTimerSetRepeat tmr newtval
evTimerAgain loop tmr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment