unbounded-delays 0.1.0.7 → 0.1.0.8
raw patch · 3 files changed
+17/−16 lines, 3 files
Files
- Control/Concurrent/Thread/Delay.hs +9/−5
- Control/Concurrent/Timeout.hs +7/−10
- unbounded-delays.cabal +1/−1
Control/Concurrent/Thread/Delay.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE CPP, NoImplicitPrelude, UnicodeSyntax #-}+{-# LANGUAGE CPP, NoImplicitPrelude #-} #if __GLASGOW_HASKELL__ >= 704 {-# LANGUAGE Safe #-}@@ -24,11 +24,11 @@ -- from base: import Control.Concurrent ( threadDelay )-import Control.Monad ( when )+import Control.Monad ( when, return ) import Data.Eq ( (/=) ) import Data.Function ( ($) ) import Data.Int ( Int )-import Data.Ord ( min )+import Data.Ord ( min, (<=) ) import Prelude ( Integer, toInteger, fromInteger, maxBound, (-) ) import System.IO ( IO ) @@ -50,8 +50,12 @@ delay has expired, but the thread will never continue to run earlier than specified. -}-delay ∷ Integer → IO ()+delay :: Integer -> IO ()+delay time | time <= 0 =+ -- When time is a big negative integer, casting it to Int may overflow.+ -- So we handle it as a special case here.+ return () delay time = do- let maxWait = min time $ toInteger (maxBound ∷ Int)+ let maxWait = min time $ toInteger (maxBound :: Int) threadDelay $ fromInteger maxWait when (maxWait /= time) $ delay (time - maxWait)
Control/Concurrent/Timeout.hs view
@@ -1,7 +1,4 @@-{-# LANGUAGE CPP- , DeriveDataTypeable- , NoImplicitPrelude- , UnicodeSyntax #-}+{-# LANGUAGE CPP, DeriveDataTypeable, NoImplicitPrelude #-} #if __GLASGOW_HASKELL__ >= 704 {-# LANGUAGE Safe #-}@@ -102,16 +99,16 @@ @select(2)@ to perform asynchronous I\/O, so it is possible to interrupt standard socket I\/O or file I\/O using this combinator. -}-timeout ∷ Integer → IO α → IO (Maybe α)+timeout :: Integer -> IO α -> IO (Maybe α) timeout n f | n < 0 = fmap Just f | n == 0 = return Nothing | otherwise = do- pid ← myThreadId- ex ← fmap Timeout newUnique- handleJust (\e → if e == ex then Just () else Nothing)- (\_ → return Nothing)+ pid <- myThreadId+ ex <- fmap Timeout newUnique+ handleJust (\e -> if e == ex then Just () else Nothing)+ (\_ -> return Nothing) (bracket (forkIO (delay n >> throwTo pid ex)) (killThread)- (\_ → fmap Just f)+ (\_ -> fmap Just f) )
unbounded-delays.cabal view
@@ -1,5 +1,5 @@ name: unbounded-delays-version: 0.1.0.7+version: 0.1.0.8 cabal-version: >= 1.6 build-type: Custom author: Bas van Dijk <v.dijk.bas@gmail.com>