-- | Register an action to be performed in the given number of seconds.  The
-- returned 'TimeoutKey' can be used to later unregister or update the timeout.
-- The timeout is automatically unregistered when it fires.
--
-- The 'TimeoutCallback' will not be called more than once.
registerTimeout :: Manager -> Seconds -> TimeoutCallback -> IO TimeoutKey
registerTimeout mgr relTime cb = do
    key <- newUnique
    now <- getTime (mgrClock mgr)
    let !expTime = now + relTime
    postMgr mgr $ modifyTQ $ Q.insert key expTime cb
    return $ TK key

-- | Update an active timeout to fire in the given number of seconds (from the
-- time 'updateTimeout' is called), instead of when it was going to fire.
-- This has no effect if the timeout has already fired.
registerTimeout :: Manager -> Seconds -> TimeoutCallback -> IO TimeoutKey
registerTimeout mgr relTime cb = do
    key <- newUnique
    now <- getTime (mgrClock mgr)
    let !expTime = now + relTime
    postMgr mgr $ modifyTQ $ Q.insert key expTime cb
    return $ TK key

-- | Update an active timeout to fire in the given number of seconds (from the
-- time 'updateTimeout' is called), instead of when it was going to fire.
-- This has no effect if the timeout has already fired.
registerTimeout mgr relTime cb = do
    key <- newUnique
    now <- getTime (mgrClock mgr)
    let !expTime = now + relTime
    postMgr mgr $ modifyTQ $ Q.insert key expTime cb
    return $ TK key

-- | Update an active timeout to fire in the given number of seconds (from the
-- time 'updateTimeout' is called), instead of when it was going to fire.
-- This has no effect if the timeout has already fired.