module Control.Spork
( spork
) where
import Control.Exception
import System.IO.Unsafe
spork
:: Exception e
=> a -> Either e a
spork :: forall e a. Exception e => a -> Either e a
spork a
a =
forall a. IO a -> a
unsafePerformIO forall a b. (a -> b) -> a -> b
$
(forall a b. b -> Either a b
Right forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` forall a. a -> IO a
evaluate a
a) forall a. IO a -> [Handler a] -> IO a
`catches` [forall a e. Exception e => (e -> IO a) -> Handler a
Handler (\e
e -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall a b. a -> Either a b
Left e
e))]
{-# INLINEABLE spork #-}