module Events.Spawn(
spawn
) where
import Control.Concurrent
import Control.Exception
spawn :: IO () -> IO (IO ())
spawn action =
do
let quietAction = goesQuietly action
threadId <- forkIO quietAction
return (killThread threadId)
goesQuietly :: IO () -> IO ()
goesQuietly action =
do
result <-
tryJust
(\ exception -> case fromException exception of
Just ThreadKilled -> Just ()
_ -> case fromException exception of
#if __GLASGOW_HASKELL__ >= 612
Just BlockedIndefinitelyOnMVar -> Just ()
#else
Just BlockedOnDeadMVar -> Just ()
#endif
_ -> Nothing
)
action
case result of
Left () -> return ()
Right () -> return ()