2-- Module : Streamly.Internal.Control.Concurrent
3-- Copyright : (c) 2017 Composewell Technologies
4-- License : BSD-3-Clause
5-- Maintainer : streamly@composewell.com
6-- Stability : experimental
9-- Note: This module is primarily for abstractions related to MonadBaseControl.
10-- Please do not add any general routines in this. It should be renamed
13module Streamly.Internal.Control.Concurrent
20 , withRunInIONoRestore
25import Control.Monad.Catch (MonadThrow)
26import Streamly.Internal.Data.SVar.Type (RunInIO(..))
29import Control.Monad.IO.Unlift (MonadUnliftIO(..), UnliftIO(..), askUnliftIO)
31import Control.Monad.IO.Class (MonadIO)
32import Control.Monad.Trans.Control (MonadBaseControl(..), control)
36type MonadRunInIO m = MonadUnliftIO m
38type MonadRunInIO m = (MonadIO m, MonadBaseControl IO m)
41-- | A monad that can perform concurrent or parallel IO operations. Streams
42-- that can be composed concurrently require the underlying monad to be
46type MonadAsync m = (MonadUnliftIO m, MonadThrow m)
48type MonadAsync m = (MonadIO m, MonadBaseControl IO m, MonadThrow m)
51-- | When we run computations concurrently, we completely isolate the state of
52-- the concurrent computations from the parent computation. The invariant is
53-- that we should never be running two concurrent computations in the same
54-- thread without using the runInIO function. Also, we should never be running
55-- a concurrent computation in the parent thread, otherwise it may affect the
56-- state of the parent which is against the defined semantics of concurrent
58askRunInIO :: MonadRunInIO m => m (RunInIO m)
60askRunInIO = fmap (\(UnliftIO run) -> RunInIO run) askUnliftIO
62askRunInIO = control $ \run -> run (return $ RunInIO run)
66withRunInIONoRestore :: MonadRunInIO m => ((forall a. m a -> IO a) -> IO b) -> m b
67withRunInIONoRestore = withRunInIO
69restoreM :: MonadRunInIO m => a -> m a
72withRunInIO :: MonadRunInIO m => ((forall a. m a -> IO (StM m a)) -> IO (StM m b)) -> m b
75withRunInIONoRestore :: MonadRunInIO m => ((forall a. m a -> IO (StM m a)) -> IO b) -> m b
76withRunInIONoRestore = liftBaseWith
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