Safe Haskell | None |
---|---|
Language | Haskell2010 |
- strictTry :: NFData a => IO a -> IO (Either SomeException a)
- try :: Exception e => IO a -> IO (Either e a)
- tryE :: IO a -> IO (Either SomeException a)
- forceE :: Either String c -> c
- data SomeException :: *
- milliseconds :: Num a => a -> a
- seconds :: Num a => a -> a
- minutes :: Num c => c -> c
- withTimeout :: Int -> IO a -> IO (Either String a)
- async :: IO a -> IO (Async a)
- cancel :: Async a -> IO ()
- threadDelay :: Int -> IO ()
- liftIO :: MonadIO m => forall a. IO a -> m a
- forever :: Applicative f => f a -> f b
- when :: Applicative f => Bool -> f () -> f ()
- unless :: Applicative f => Bool -> f () -> f ()
- dbg :: MonadIO m => [String] -> m ()
- warn :: MonadIO m => [String] -> m ()
- info :: MonadIO m => [String] -> m ()
- err :: MonadIO m => [String] -> m ()
- dbgS :: String -> IO ()
- logLevel :: Priority -> IO ()
- logLevelOut :: Priority -> Handle -> IO ()
- eitherToMaybe :: Either t a -> Maybe a
Exceptions
strictTry :: NFData a => IO a -> IO (Either SomeException a) Source #
Strict try, deepseq
s the returned value
try :: Exception e => IO a -> IO (Either e a) #
Similar to catch
, but returns an Either
result which is
(
if no exception of type Right
a)e
was raised, or (
if an exception of type Left
ex)e
was raised and its value is ex
.
If any other type of exception is raised than it will be propogated
up to the next enclosing exception handler.
try a = catch (Right `liftM` a) (return . Left)
tryE :: IO a -> IO (Either SomeException a) Source #
Like try
but with returned exception fixed to SomeException
data SomeException :: * #
The SomeException
type is the root of the exception type hierarchy.
When an exception of type e
is thrown, behind the scenes it is
encapsulated in a SomeException
.
Time
milliseconds :: Num a => a -> a Source #
Convert milliseconds to microseconds (μs)
:: Int | Timeout (in seconds) |
-> IO a | Op to execute |
-> IO (Either String a) | Right if op completed correctly, Left otherwise withTimeout secs op = maybe (Left Timeout) Right $ timeout (seconds secs) op |
Run an IO op with a timeout
Threads
Cancel an asynchronous action by throwing the ThreadKilled
exception to it, and waiting for the Async
thread to quit.
Has no effect if the Async
has already completed.
cancel a = throwTo (asyncThreadId a) ThreadKilled <* waitCatch a
Note that cancel
will not terminate until the thread the Async
refers to has terminated. This means that cancel
will block for
as long said thread blocks when receiving an asynchronous exception.
For example, it could block if:
- It's executing a foreign call, and thus cannot receive the asynchronous exception;
- It's executing some cleanup handler after having received the exception, and the handler is blocking.
threadDelay :: Int -> IO () #
Suspends the current thread for a given number of microseconds (GHC only).
There is no guarantee that the thread will be rescheduled promptly when the delay has expired, but the thread will never continue to run earlier than specified.
Monads
forever :: Applicative f => f a -> f b #
repeats the action infinitely.forever
act
when :: Applicative f => Bool -> f () -> f () #
Conditional execution of Applicative
expressions. For example,
when debug (putStrLn "Debugging")
will output the string Debugging
if the Boolean value debug
is True
, and otherwise do nothing.
unless :: Applicative f => Bool -> f () -> f () #
The reverse of when
.
Logging (with native ghcjs support)
Other
eitherToMaybe :: Either t a -> Maybe a Source #
Convert an Either to a Maybe