| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Control.Timeout
Documentation
timeout :: (TimeUnit t, MonadIO m, MonadCatch m) => t -> m a -> m (Maybe a) Source
Run a monadic action with a time limit. If it finishes before that time
passes and returns value x, then Just x is returned. If the timeout
passes, the action is aborted and Nothing is returned. If the action
throws an exception, it is aborted and the exception is rethrown.
>>>timeout (3 :: Second) $ delay (1 :: Second) >> return "hello"Just "hello"
>>>timeout (3 :: Second) $ delay (5 :: Second) >> return "hello"Nothing
>>>timeout (1 :: Second) $ error "hello"*** Exception: hello