runExpiredTimeouts :: Manager -> Mgr (Maybe Seconds)
runExpiredTimeouts Manager{..} = do
    empty <- getsTQ Q.null
    if empty then
        return Nothing
    else do
        now <- liftIO $ getTime mgrClock
        stateTQ (Q.atMost now) >>= mapM_ (liftIO . Q.value)
        next <- getsTQ $ fmap Q.prio . Q.findMin
        case next of
            Nothing ->
                return Nothing
            Just t -> do
                -- This value will always be positive since the call
                -- to 'atMost' above removed any timeouts <= 'now'
                let !t' = t - now
                return $ Just t'

-- | Return the delay argument to pass to GetQueuedCompletionStatus.
runExpiredTimeouts :: Manager -> Mgr (Maybe Seconds)
runExpiredTimeouts Manager{..} = do
    empty <- getsTQ Q.null
    if empty then
        return Nothing
    else do
        now <- liftIO $ getTime mgrClock
        stateTQ (Q.atMost now) >>= mapM_ (liftIO . Q.value)
        next <- getsTQ $ fmap Q.prio . Q.findMin
        case next of
            Nothing ->
                return Nothing
            Just t -> do
                -- This value will always be positive since the call
                -- to 'atMost' above removed any timeouts <= 'now'
                let !t' = t - now
                return $ Just t'

-- | Return the delay argument to pass to GetQueuedCompletionStatus.
runExpiredTimeouts Manager{..} = do
    empty <- getsTQ Q.null
    if empty then
        return Nothing
    else do
        now <- liftIO $ getTime mgrClock
        stateTQ (Q.atMost now) >>= mapM_ (liftIO . Q.value)
        next <- getsTQ $ fmap Q.prio . Q.findMin
        case next of
            Nothing ->
                return Nothing
            Just t -> do
                -- This value will always be positive since the call
                -- to 'atMost' above removed any timeouts <= 'now'
                let !t' = t - now
                return $ Just t'

-- | Return the delay argument to pass to GetQueuedCompletionStatus.