2-- Module : Streamly.Internal.Control.ForkLifted
3-- Copyright : (c) 2017 Composewell Technologies
4-- License : BSD-3-Clause
5-- Maintainer : streamly@composewell.com
6-- Stability : experimental
9module Streamly.Internal.Control.ForkLifted
17import Control.Concurrent (ThreadId, forkIO)
18import Control.Exception (SomeException(..), catch, mask)
19import Data.Functor (void)
20import Streamly.Internal.Control.Concurrent (MonadRunInIO, RunInIO(..), withRunInIO, withRunInIONoRestore)
21import Streamly.Internal.Control.ForkIO (rawForkIO, forkManagedWith)
23-- | Fork a thread to run the given computation, installing the provided
24-- exception handler. Lifted to any monad with 'MonadRunInIO m'
27-- TODO: the RunInIO argument can be removed, we can directly pass the action
28-- as "mrun action" instead.
30doFork :: MonadRunInIO m
33 -> (SomeException -> IO ())
35doFork action (RunInIO mrun) exHandler =
38 tid <- rawForkIO $ catch (restore $ void $ mrun action)
42-- | 'fork' lifted to any monad with 'MonadBaseControl IO m' capability.
45fork :: MonadRunInIO m => m () -> m ThreadId
46fork m = withRunInIONoRestore $ \run -> forkIO $ void $ run m
48-- | Fork a thread that is automatically killed as soon as the reference to the
49-- returned threadId is garbage collected.
51{-# INLINABLE forkManaged #-}
52forkManaged :: MonadRunInIO m => m () -> m ThreadId
53forkManaged = forkManagedWith fork
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list