From 94d448d7f730854a921293f71787864b76b6b267 Mon Sep 17 00:00:00 2001 From: Ross Paterson Date: Tue, 12 Aug 2008 15:16:02 +0000 Subject: [PATCH] use dummy implementation of timeout for all non-GHCs --- System/Timeout.hs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/System/Timeout.hs b/System/Timeout.hs index 959e1a2..9ccc634 100644 --- a/System/Timeout.hs +++ b/System/Timeout.hs @@ -12,21 +12,19 @@ -- ------------------------------------------------------------------------------- +#ifdef __GLASGOW_HASKELL__ #include "Typeable.h" +#endif module System.Timeout ( timeout ) where -#if __NHC__ -timeout :: Int -> IO a -> IO (Maybe a) -timeout n f = fmap Just f -#else - +#ifdef __GLASGOW_HASKELL__ import Prelude (Show(show), IO, Ord((<)), Eq((==)), Int, (.), otherwise, fmap) import Data.Maybe (Maybe(..)) import Control.Monad (Monad(..), guard) import Control.Concurrent (forkIO, threadDelay, myThreadId, killThread) -import Control.Exception.Base (Exception, handleJust, throwTo, bracket) +import Control.Exception (Exception, handleJust, throwTo, bracket) import Data.Dynamic (Typeable, fromDynamic) import Data.Typeable import Data.Unique (Unique, newUnique) @@ -42,6 +40,7 @@ instance Show Timeout where show _ = "<>" instance Exception Timeout +#endif /* !__GLASGOW_HASKELL__ */ -- |Wrap an 'IO' computation to time out and return @Nothing@ in case no result -- is available within @n@ microseconds (@1\/10^6@ seconds). In case a result @@ -73,6 +72,7 @@ instance Exception Timeout -- I\/O or file I\/O using this combinator. timeout :: Int -> IO a -> IO (Maybe a) +#ifdef __GLASGOW_HASKELL__ timeout n f | n < 0 = fmap Just f | n == 0 = return Nothing @@ -84,4 +84,6 @@ timeout n f (bracket (forkIO (threadDelay n >> throwTo pid ex)) (killThread) (\_ -> fmap Just f)) -#endif +#else +timeout n f = fmap Just f +#endif /* !__GLASGOW_HASKELL__ */ -- 1.7.10.4