summaryrefslogtreecommitdiff
path: root/libraries/base/System/Timeout.hs
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/base/System/Timeout.hs')
-rw-r--r--libraries/base/System/Timeout.hs11
1 files changed, 8 insertions, 3 deletions
diff --git a/libraries/base/System/Timeout.hs b/libraries/base/System/Timeout.hs
index d34082e64f..e2b85658bb 100644
--- a/libraries/base/System/Timeout.hs
+++ b/libraries/base/System/Timeout.hs
@@ -35,9 +35,9 @@ import Data.Unique (Unique, newUnique)
-- interrupt the running IO computation when the timeout has
-- expired.
-newtype Timeout = Timeout Unique deriving (Eq)
+newtype Timeout = Timeout Unique deriving Eq -- ^ @since 4.0
--- | @since 3.0
+-- | @since 4.0
instance Show Timeout where
show _ = "<<timeout>>"
@@ -53,6 +53,12 @@ instance Exception Timeout where
-- timeout interval means \"wait indefinitely\". When specifying long timeouts,
-- be careful not to exceed @maxBound :: Int@.
--
+-- >>> timeout 1000000 (threadDelay 1000 *> pure "finished on time")
+-- Just "finished on time"
+--
+-- >>> timeout 10000 (threadDelay 100000 *> pure "finished on time")
+-- Nothing
+--
-- The design of this combinator was guided by the objective that @timeout n f@
-- should behave exactly the same as @f@ as long as @f@ doesn't time out. This
-- means that @f@ has the same 'myThreadId' it would have without the timeout
@@ -75,7 +81,6 @@ instance Exception Timeout where
-- because the runtime system uses scheduling mechanisms like @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 :: Int -> IO a -> IO (Maybe a)
timeout n f
| n < 0 = fmap Just f