packages feed

unliftio 0.1.0.0 → 0.1.1.0

raw patch · 14 files changed

+407/−159 lines, 14 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ UnliftIO.Concurrent: data ThreadId :: *
+ UnliftIO.Concurrent: forkFinally :: MonadUnliftIO m => m a -> (Either SomeException a -> m ()) -> m ThreadId
+ UnliftIO.Concurrent: forkIO :: MonadUnliftIO m => m () -> m ThreadId
+ UnliftIO.Concurrent: forkOS :: MonadUnliftIO m => m () -> m ThreadId
+ UnliftIO.Concurrent: forkOn :: MonadUnliftIO m => Int -> m () -> m ThreadId
+ UnliftIO.Concurrent: forkOnWithUnmask :: MonadUnliftIO m => Int -> ((forall a. m a -> m a) -> m ()) -> m ThreadId
+ UnliftIO.Concurrent: forkWithUnmask :: MonadUnliftIO m => ((forall a. m a -> m a) -> m ()) -> m ThreadId
+ UnliftIO.Concurrent: getNumCapabilities :: MonadIO m => m Int
+ UnliftIO.Concurrent: isCurrentThreadBound :: MonadIO m => m Bool
+ UnliftIO.Concurrent: killThread :: MonadIO m => ThreadId -> m ()
+ UnliftIO.Concurrent: mkWeakThreadId :: MonadIO m => ThreadId -> m (Weak ThreadId)
+ UnliftIO.Concurrent: myThreadId :: MonadIO m => m ThreadId
+ UnliftIO.Concurrent: rtsSupportsBoundThreads :: Bool
+ UnliftIO.Concurrent: runInBoundThread :: MonadUnliftIO m => m a -> m a
+ UnliftIO.Concurrent: runInUnboundThread :: MonadUnliftIO m => m a -> m a
+ UnliftIO.Concurrent: setNumCapabilities :: MonadIO m => Int -> m ()
+ UnliftIO.Concurrent: threadCapability :: MonadIO m => ThreadId -> m (Int, Bool)
+ UnliftIO.Concurrent: threadDelay :: MonadIO m => Int -> m ()
+ UnliftIO.Concurrent: threadWaitRead :: MonadIO m => Fd -> m ()
+ UnliftIO.Concurrent: threadWaitWrite :: MonadIO m => Fd -> m ()
+ UnliftIO.Concurrent: throwTo :: (Exception e, MonadIO m) => ThreadId -> e -> m ()
+ UnliftIO.Concurrent: yield :: MonadIO m => m ()
- UnliftIO.Chan: dupChan :: Chan a -> IO (Chan a)
+ UnliftIO.Chan: dupChan :: MonadIO m => Chan a -> m (Chan a)
- UnliftIO.Chan: getChanContents :: Chan a -> IO [a]
+ UnliftIO.Chan: getChanContents :: MonadIO m => Chan a -> m [a]
- UnliftIO.Chan: readChan :: Chan a -> IO a
+ UnliftIO.Chan: readChan :: MonadIO m => Chan a -> m a
- UnliftIO.Chan: writeChan :: Chan a -> a -> IO ()
+ UnliftIO.Chan: writeChan :: MonadIO m => Chan a -> a -> m ()
- UnliftIO.Chan: writeList2Chan :: Chan a -> [a] -> IO ()
+ UnliftIO.Chan: writeList2Chan :: MonadIO m => Chan a -> [a] -> m ()

Files

ChangeLog.md view
@@ -1,3 +1,9 @@+## 0.1.1.0++* Doc improvements.+* Fix `UnliftIO.Chan` type signatures [#3](https://github.com/fpco/unliftio/pull/3).+* Add `UnliftIO.Concurrent` module [#5](https://github.com/fpco/unliftio/pull/5).+ ## 0.1.0.0 -* Initial release+* Initial release.
README.md view
@@ -129,10 +129,22 @@ simply add the `MonadUnliftIO` constraint and then use the pre-unlifted versions of functions (like `UnliftIO.Exception.catch`). But ultimately, you'll probably want to-use the typeclass directly. Here are some simple examples. First: ome-typeclass instances:+use the typeclass directly. The type class has only one method --+`askUnliftIO`:  ```haskell+newtype UnliftIO m = UnliftIO { unliftIO :: forall a. m a -> IO a }++class MonadIO m => MonadUnliftIO m where+  askUnliftIO :: m (UnliftIO m)+```++`askUnliftIO` gives us a function to run arbitrary computation in `m`+in `IO`. Thus the "unlift": it's like `liftIO`, but the other way around.++Here are some sample typeclass instances:++```haskell instance MonadUnliftIO IO where   askUnliftIO = return (UnliftIO id) instance MonadUnliftIO m => MonadUnliftIO (IdentityT m) where@@ -155,21 +167,41 @@ * `ReaderT` is just like `IdentityT`, but it captures the reader   environment when starting. -Second, using `withRunInIO` to unlift a function:+We can use `askUnliftIO` to unlift a function:  ```haskell timeout :: MonadUnliftIO m => Int -> m a -> m (Maybe a)+timeout x y = do+  u <- askUnliftIO+  System.Timeout.timeout x $ unliftIO u y+```++or more concisely using `withRunIO`:++```haskell+timeout :: MonadUnliftIO m => Int -> m a -> m (Maybe a) timeout x y = withRunInIO $ \run -> System.Timeout.timeout x $ run y ```  This is a common pattern: use `withRunInIO` to capture a run function, and then call the original function with the user-supplied arguments,-applying `run` as necessary.+applying `run` as necessary. `withRunIO` takes care of invoking+`unliftIO` for us. -Thirdly, using `askUnliftIO` directly when multiple types are needed:+However, if we want to use the run function with different types, we+must use `askUnliftIO`:  ```haskell race :: MonadUnliftIO m => m a -> m b -> m (Either a b)+race a b = do+  u <- askUnliftIO+  liftIO (A.race (unliftIO u a) (unliftIO u b))+```++or more idiomatically `withUnliftIO`:++```haskell+race :: MonadUnliftIO m => m a -> m b -> m (Either a b) race a b = withUnliftIO $ \u -> A.race (unliftIO u a) (unliftIO u b) ``` @@ -178,7 +210,7 @@ `withRunInIO` calls here instead, but this approach is idiomatic and may be more performant (depending on optimizations). -And finally, a much more complex usage, when unlifting the `mask`+And finally, a more complex usage, when unlifting the `mask` function. This function needs to unlift vaues to be passed into the `restore` function, and then `liftIO` the result of the `restore` function.@@ -284,7 +316,10 @@  * `MonadUnliftIO` is a simple typeclass, easy to explain. We don't   want to complicated matters (`MonadBaseControl` is a notoriously-  difficult to understand typeclass)+  difficult to understand typeclass). This simplicity+  is captured by the laws for `MonadUnliftIO`, which make the+  behavior of the run functions close to that of the already familiar+  `lift` and `liftIO`. * Having this kind of split would be confusing in user code, when   suddenly `finally` is not available to us. We would rather encourage   [good practices](https://www.fpcomplete.com/blog/2017/06/readert-design-pattern)
src/UnliftIO/Async.hs view
@@ -1,6 +1,6 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE RankNTypes #-}--- | Unlifted "Control.Concurrent.Async"+-- | Unlifted "Control.Concurrent.Async". -- -- @since 0.1.0.0 module UnliftIO.Async@@ -62,57 +62,57 @@ import Data.Traversable (Traversable) #endif --- | Unlift 'A.async'+-- | Unlifted 'A.async'. -- -- @since 0.1.0.0 async :: MonadUnliftIO m => m a -> m (Async a) async m = withRunInIO $ \run -> A.async $ run m --- | Unlift 'A.asyncBound'+-- | Unlifted 'A.asyncBound'. -- -- @since 0.1.0.0 asyncBound :: MonadUnliftIO m => m a -> m (Async a) asyncBound m = withRunInIO $ \run -> A.asyncBound $ run m --- | Unlift 'A.asyncOn'+-- | Unlifted 'A.asyncOn'. -- -- @since 0.1.0.0 asyncOn :: MonadUnliftIO m => Int -> m a -> m (Async a) asyncOn i m = withRunInIO $ \run -> A.asyncOn i $ run m --- | Unlift 'A.asyncWithUnmask'+-- | Unlifted 'A.asyncWithUnmask'. -- -- @since 0.1.0.0 asyncWithUnmask :: MonadUnliftIO m => ((forall b. m b -> m b) -> m a) -> m (Async a) asyncWithUnmask m =   withUnliftIO $ \u -> A.asyncWithUnmask $ \unmask -> unliftIO u $ m $ liftIO . unmask . unliftIO u --- | Unlift 'A.asyncOnWithUnmask'+-- | Unlifted 'A.asyncOnWithUnmask'. -- -- @since 0.1.0.0 asyncOnWithUnmask :: MonadUnliftIO m => Int -> ((forall b. m b -> m b) -> m a) -> m (Async a) asyncOnWithUnmask i m =   withUnliftIO $ \u -> A.asyncOnWithUnmask i $ \unmask -> unliftIO u $ m $ liftIO . unmask . unliftIO u --- | Unlift 'A.withAsync'+-- | Unlifted 'A.withAsync'. -- -- @since 0.1.0.0 withAsync :: MonadUnliftIO m => m a -> (Async a -> m b) -> m b withAsync a b = withUnliftIO $ \u -> A.withAsync (unliftIO u a) (unliftIO u . b) --- | Unlift 'A.withAsyncBound'+-- | Unlifted 'A.withAsyncBound'. -- -- @since 0.1.0.0 withAsyncBound :: MonadUnliftIO m => m a -> (Async a -> m b) -> m b withAsyncBound a b = withUnliftIO $ \u -> A.withAsyncBound (unliftIO u a) (unliftIO u . b) --- | Unlift 'A.withAsyncOn'+-- | Unlifted 'A.withAsyncOn'. -- -- @since 0.1.0.0 withAsyncOn :: MonadUnliftIO m => Int -> m a -> (Async a -> m b) -> m b withAsyncOn i a b = withUnliftIO $ \u -> A.withAsyncOn i (unliftIO u a) (unliftIO u . b) --- | Unlift 'A.withAsyncWithUnmask'+-- | Unlifted 'A.withAsyncWithUnmask'. -- -- @since 0.1.0.0 withAsyncWithUnmask@@ -125,7 +125,7 @@     (\unmask -> unliftIO u $ a $ liftIO . unmask . unliftIO u)     (unliftIO u . b) --- | Unlift 'A.withAsyncOnWithMask'+-- | Unlifted 'A.withAsyncOnWithMask'. -- -- @since 0.1.0.0 withAsyncOnWithUnmask@@ -139,31 +139,31 @@     (\unmask -> unliftIO u $ a $ liftIO . unmask . unliftIO u)     (unliftIO u . b) --- | Lifted 'A.wait'+-- | Lifted 'A.wait'. -- -- @since 0.1.0.0 wait :: MonadIO m => Async a -> m a wait = liftIO . A.wait --- | Lifted 'A.poll'+-- | Lifted 'A.poll'. -- -- @since 0.1.0.0 poll :: MonadIO m => Async a -> m (Maybe (Either SomeException a)) poll = liftIO . A.poll --- | Lifted 'A.waitCatch'+-- | Lifted 'A.waitCatch'. -- -- @since 0.1.0.0 waitCatch :: MonadIO m => Async a -> m (Either SomeException a) waitCatch = liftIO . A.waitCatch --- | Lifted 'A.cancel'+-- | Lifted 'A.cancel'. -- -- @since 0.1.0.0 cancel :: MonadIO m => Async a -> m () cancel = liftIO . A.cancel --- | Lifted 'A.uninterruptibleCancel'+-- | Lifted 'A.uninterruptibleCancel'. -- -- @since 0.1.0.0 uninterruptibleCancel :: MonadIO m => Async a -> m ()@@ -176,139 +176,139 @@ cancelWith :: (Exception e, MonadIO m) => Async a -> e -> m () cancelWith a e = liftIO (A.cancelWith a (E.toAsyncException e)) --- | Lifted 'A.waitAny'+-- | Lifted 'A.waitAny'. -- -- @since 0.1.0.0 waitAny :: MonadIO m => [Async a] -> m (Async a, a) waitAny = liftIO . A.waitAny --- | Lifted 'A.waitAnyCatch'+-- | Lifted 'A.waitAnyCatch'. -- -- @since 0.1.0.0 waitAnyCatch :: MonadIO m => [Async a] -> m (Async a, Either SomeException a) waitAnyCatch = liftIO . A.waitAnyCatch --- | Lifted 'A.waitAnyCancel'+-- | Lifted 'A.waitAnyCancel'. -- -- @since 0.1.0.0 waitAnyCancel :: MonadIO m => [Async a] -> m (Async a, a) waitAnyCancel = liftIO . A.waitAnyCancel --- | Lifted 'A.waitAnyCatchCancel'+-- | Lifted 'A.waitAnyCatchCancel'. -- -- @since 0.1.0.0 waitAnyCatchCancel :: MonadIO m => [Async a] -> m (Async a, Either SomeException a) waitAnyCatchCancel = liftIO . A.waitAnyCatchCancel --- | Lifted 'A.waitEither'+-- | Lifted 'A.waitEither'. -- -- @since 0.1.0.0 waitEither :: MonadIO m => Async a -> Async b -> m (Either a b) waitEither a b = liftIO (A.waitEither a b) --- | Lifted 'A.waitEitherCatch'+-- | Lifted 'A.waitEitherCatch'. -- -- @since 0.1.0.0 waitEitherCatch :: MonadIO m => Async a -> Async b -> m (Either (Either SomeException a) (Either SomeException b)) waitEitherCatch a b = liftIO (A.waitEitherCatch a b) --- | Lifted 'A.waitEitherCancel'+-- | Lifted 'A.waitEitherCancel'. -- -- @since 0.1.0.0 waitEitherCancel :: MonadIO m => Async a -> Async b -> m (Either a b) waitEitherCancel a b = liftIO (A.waitEitherCancel a b) --- | Lifted 'A.waitEitherCatchCancel'+-- | Lifted 'A.waitEitherCatchCancel'. -- -- @since 0.1.0.0 waitEitherCatchCancel :: MonadIO m => Async a -> Async b -> m (Either (Either SomeException a) (Either SomeException b)) waitEitherCatchCancel a b = liftIO (A.waitEitherCatchCancel a b) --- | Lifted 'A.waitEither_'+-- | Lifted 'A.waitEither_'. -- -- @since 0.1.0.0 waitEither_ :: MonadIO m => Async a -> Async b -> m () waitEither_ a b = liftIO (A.waitEither_ a b) --- | Lifted 'A.waitBoth'+-- | Lifted 'A.waitBoth'. -- -- @since 0.1.0.0 waitBoth :: MonadIO m => Async a -> Async b -> m (a, b) waitBoth a b = liftIO (A.waitBoth a b) --- | Lifted 'A.link'+-- | Lifted 'A.link'. -- -- @since 0.1.0.0 link :: MonadIO m => Async a -> m () link = liftIO . A.link --- | Lifted 'A.link2'+-- | Lifted 'A.link2'. -- -- @since 0.1.0.0 link2 :: MonadIO m => Async a -> Async b -> m () link2 a b = liftIO (A.link2 a b) --- | Unlifted 'A.race'+-- | Unlifted 'A.race'. -- -- @since 0.1.0.0 race :: MonadUnliftIO m => m a -> m b -> m (Either a b) race a b = withUnliftIO $ \u -> A.race (unliftIO u a) (unliftIO u b) --- | Unlifted 'A.race_'+-- | Unlifted 'A.race_'. -- -- @since 0.1.0.0 race_ :: MonadUnliftIO m => m a -> m b -> m () race_ a b = withUnliftIO $ \u -> A.race_ (unliftIO u a) (unliftIO u b) --- | Unlifted 'A.concurrently'+-- | Unlifted 'A.concurrently'. -- -- @since 0.1.0.0 concurrently :: MonadUnliftIO m => m a -> m b -> m (a, b) concurrently a b = withUnliftIO $ \u -> A.concurrently (unliftIO u a) (unliftIO u b) --- | Unlifted 'A.concurrently_'+-- | Unlifted 'A.concurrently_'. -- -- @since 0.1.0.0 concurrently_ :: MonadUnliftIO m => m a -> m b -> m () concurrently_ a b = withUnliftIO $ \u -> A.concurrently_ (unliftIO u a) (unliftIO u b) --- | Unlifted 'A.mapConcurrently'+-- | Unlifted 'A.mapConcurrently'. -- -- @since 0.1.0.0 mapConcurrently :: MonadUnliftIO m => Traversable t => (a -> m b) -> t a -> m (t b) mapConcurrently f t = withRunInIO $ \run -> A.mapConcurrently (run . f) t --- | Unlifted 'A.forConcurrently'+-- | Unlifted 'A.forConcurrently'. -- -- @since 0.1.0.0 forConcurrently :: MonadUnliftIO m => Traversable t => t a -> (a -> m b) -> m (t b) forConcurrently t f = withRunInIO $ \run -> A.forConcurrently t (run . f) --- | Unlifted 'A.mapConcurrently_'+-- | Unlifted 'A.mapConcurrently_'. -- -- @since 0.1.0.0 mapConcurrently_ :: MonadUnliftIO m => Foldable f => (a -> m b) -> f a -> m () mapConcurrently_ f t = withRunInIO $ \run -> A.mapConcurrently_ (run . f) t --- | Unlifted 'A.forConcurrently_'+-- | Unlifted 'A.forConcurrently_'. -- -- @since 0.1.0.0 forConcurrently_ :: MonadUnliftIO m => Foldable f => f a -> (a -> m b) -> m () forConcurrently_ t f = withRunInIO $ \run -> A.forConcurrently_ t (run . f) --- | Unlifted 'A.replicateConcurrently'+-- | Unlifted 'A.replicateConcurrently'. -- -- @since 0.1.0.0 replicateConcurrently :: MonadUnliftIO m => Int -> m a -> m [a] replicateConcurrently i m = withRunInIO $ \run -> A.replicateConcurrently i (run m) --- | Unlifted 'A.replicateConcurrently_'+-- | Unlifted 'A.replicateConcurrently_'. -- -- @since 0.1.0.0 replicateConcurrently_ :: MonadUnliftIO m => Int -> m a -> m () replicateConcurrently_ i m = withRunInIO $ \run -> A.replicateConcurrently_ i (run m) --- | Unlifted 'A.Concurrently'+-- | Unlifted 'A.Concurrently'. -- -- @since 0.1.0.0 newtype Concurrently m a = Concurrently@@ -332,7 +332,7 @@     Concurrently $ liftM (either id id) (race as bs)  #if MIN_VERSION_base(4,9,0)--- | Only defined by @async@ for @base >= 4.9@+-- | Only defined by @async@ for @base >= 4.9@. -- -- @since 0.1.0.0 instance (MonadUnliftIO m, Semigroup a) => Semigroup (Concurrently m a) where
src/UnliftIO/Chan.hs view
@@ -1,4 +1,4 @@--- | Lifted "Control.Concurrent.Chan"+-- | Lifted "Control.Concurrent.Chan". -- -- @since 0.1.0.0 module UnliftIO.Chan@@ -15,38 +15,38 @@ import Control.Concurrent.Chan (Chan) import qualified Control.Concurrent.Chan as C --- | Lifted 'C.newChan'+-- | Lifted 'C.newChan'. -- -- @since 0.1.0.0 newChan :: MonadIO m => m (Chan a) newChan = liftIO C.newChan --- | Lifted 'C.writeChan'+-- | Lifted 'C.writeChan'. -- -- @since 0.1.0.0-writeChan :: Chan a -> a -> IO ()+writeChan :: MonadIO m => Chan a -> a -> m () writeChan c = liftIO . C.writeChan c --- | Lifted 'C.readChan'+-- | Lifted 'C.readChan'. -- -- @since 0.1.0.0-readChan :: Chan a -> IO a+readChan :: MonadIO m => Chan a -> m a readChan = liftIO . C.readChan --- | Lifted 'C.dupChan'+-- | Lifted 'C.dupChan'. -- -- @since 0.1.0.0-dupChan :: Chan a -> IO (Chan a)+dupChan :: MonadIO m => Chan a -> m (Chan a) dupChan = liftIO . C.dupChan --- | Lifted 'C.getChanContents'+-- | Lifted 'C.getChanContents'. -- -- @since 0.1.0.0-getChanContents :: Chan a -> IO [a]+getChanContents :: MonadIO m => Chan a -> m [a] getChanContents = liftIO . C.getChanContents --- | Lifted 'C.writeList2Chan'+-- | Lifted 'C.writeList2Chan'. -- -- @since 0.1.0.0-writeList2Chan :: Chan a -> [a] -> IO ()+writeList2Chan :: MonadIO m => Chan a -> [a] -> m () writeList2Chan c = liftIO . C.writeList2Chan c
+ src/UnliftIO/Concurrent.hs view
@@ -0,0 +1,180 @@+{-# LANGUAGE RankNTypes #-}+-- | Unlifted "Control.Concurrent".+--+-- This module is not reexported by "UnliftIO",+-- use it only if "UnliftIO.Async" is not enough.+--+-- @since 0.1.1.0+module UnliftIO.Concurrent+  (+    -- * Concurrent Haskell+    ThreadId,++    -- * Basic concurrency operations+    myThreadId, forkIO, forkWithUnmask, forkFinally, killThread, throwTo,++    -- ** Threads with affinity+    forkOn, forkOnWithUnmask, getNumCapabilities, setNumCapabilities,+    threadCapability,++    -- * Scheduling+    yield,++    -- ** Waiting+    threadDelay, threadWaitRead, threadWaitWrite,++    -- * Communication abstractions+    module UnliftIO.MVar, module UnliftIO.Chan,++    -- * Bound Threads+    C.rtsSupportsBoundThreads, forkOS, isCurrentThreadBound, runInBoundThread,+    runInUnboundThread,++    -- * Weak references to ThreadIds+    mkWeakThreadId+  ) where++import Control.Monad.IO.Class (MonadIO, liftIO)+import System.Posix.Types (Fd)+import System.Mem.Weak (Weak)+import Control.Concurrent (ThreadId)+import qualified Control.Concurrent as C+import Control.Monad.IO.Unlift+import UnliftIO.MVar+import UnliftIO.Chan+import UnliftIO.Exception (throwTo, SomeException)++-- | Lifted version of 'C.myThreadId'.+--+-- @since 0.1.1.0+myThreadId :: MonadIO m => m ThreadId+myThreadId = liftIO C.myThreadId+{-# INLINABLE myThreadId #-}++-- | Unlifted version of 'C.forkIO'.+--+-- @since 0.1.1.0+forkIO :: MonadUnliftIO m => m () -> m ThreadId+forkIO m = withRunInIO $ \run -> C.forkIO $ run m+{-# INLINABLE forkIO #-}++-- | Unlifted version of 'C.forkIOWithUnmask'.+--+-- @since 0.1.1.0+forkWithUnmask :: MonadUnliftIO m => ((forall a. m a -> m a) -> m ()) -> m ThreadId+forkWithUnmask m =+  withUnliftIO $ \u -> C.forkIOWithUnmask $ \unmask -> unliftIO u $ m $ liftIO . unmask . unliftIO u+{-# INLINABLE forkWithUnmask #-}++-- | Unlifted version of 'C.forkFinally'.+--+-- @since 0.1.1.0+forkFinally :: MonadUnliftIO m => m a -> (Either SomeException a -> m ()) -> m ThreadId+forkFinally m1 m2 = withUnliftIO $ \u -> C.forkFinally (unliftIO u m1) $ unliftIO u . m2+{-# INLINABLE forkFinally #-}++-- | Lifted version of 'C.killThread'.+--+-- @since 0.1.1.0+killThread :: MonadIO m => ThreadId -> m ()+killThread = liftIO . C.killThread+{-# INLINABLE  killThread #-}++-- | Unlifted version of 'C.forkOn'.+--+-- @since 0.1.1.0+forkOn :: MonadUnliftIO m => Int -> m () -> m ThreadId+forkOn i m = withRunInIO $ \run -> C.forkOn i $ run m+{-# INLINABLE forkOn #-}++-- | Unlifted version of 'C.forkOnWithUnmask'.+--+-- @since 0.1.1.0+forkOnWithUnmask :: MonadUnliftIO m => Int -> ((forall a. m a -> m a) -> m ()) -> m ThreadId+forkOnWithUnmask i m =+  withUnliftIO $ \u -> C.forkOnWithUnmask i $ \unmask -> unliftIO u $ m $ liftIO . unmask . unliftIO u+{-# INLINABLE forkOnWithUnmask #-}++-- | Lifted version of 'C.getNumCapabilities'.+--+-- @since 0.1.1.0+getNumCapabilities :: MonadIO m => m Int+getNumCapabilities = liftIO C.getNumCapabilities+{-# INLINABLE getNumCapabilities #-}++-- | Lifted version of 'C.setNumCapabilities'.+--+-- @since 0.1.1.0+setNumCapabilities :: MonadIO m => Int -> m ()+setNumCapabilities = liftIO . C.setNumCapabilities+{-# INLINABLE setNumCapabilities #-}++-- | Lifted version of 'C.threadCapability'.+--+-- @since 0.1.1.0+threadCapability :: MonadIO m => ThreadId -> m (Int, Bool)+threadCapability = liftIO . C.threadCapability+{-# INLINABLE threadCapability #-}++-- | Lifted version of 'C.yield'.+--+-- @since 0.1.1.0+yield :: MonadIO m => m ()+yield = liftIO C.yield+{-# INLINABLE yield #-}++-- | Lifted version of 'C.threadDelay'.+--+-- @since 0.1.1.0+threadDelay :: MonadIO m => Int -> m ()+threadDelay = liftIO .  C.threadDelay+{-# INLINABLE threadDelay #-}++-- | Lifted version of 'C.threadWaitRead'.+--+-- @since 0.1.1.0+threadWaitRead :: MonadIO m => Fd -> m ()+threadWaitRead = liftIO . C.threadWaitRead+{-# INLINABLE threadWaitRead #-}++-- | Lifted version of 'C.threadWaitWrite'.+--+-- @since 0.1.1.0+threadWaitWrite :: MonadIO m => Fd -> m ()+threadWaitWrite = liftIO . C.threadWaitWrite+{-# INLINABLE threadWaitWrite #-}++-- | Unflifted version of 'C.forkOS'.+--+-- @since 0.1.1.0+forkOS :: MonadUnliftIO m => m () -> m ThreadId+forkOS m = withRunInIO $ \run -> C.forkOS $ run m+{-# INLINABLE forkOS #-}++-- | Lifted version of 'C.isCurrentThreadBound'.+--+-- @since 0.1.1.0+isCurrentThreadBound :: MonadIO m => m Bool+isCurrentThreadBound = liftIO C.isCurrentThreadBound+{-# INLINABLE isCurrentThreadBound #-}++-- | Unlifted version of 'C.runInBoundThread'.+--+-- @since 0.1.1.0+runInBoundThread :: MonadUnliftIO m => m a -> m a+runInBoundThread m = withRunInIO $ \run -> C.runInBoundThread $ run m+{-# INLINABLE runInBoundThread #-}++-- | Unlifted version of 'C.runInUnboundThread'.+--+-- @since 0.1.1.0+runInUnboundThread :: MonadUnliftIO m => m a -> m a+runInUnboundThread m = withRunInIO $ \run -> C.runInUnboundThread $ run m+{-# INLINABLE runInUnboundThread #-}++-- | Lifted version of 'C.mkWeakThreadId'.+--+-- @since 0.1.1.0+mkWeakThreadId :: MonadIO m => ThreadId -> m (Weak ThreadId)+mkWeakThreadId = liftIO . C.mkWeakThreadId+{-# INLINABLE mkWeakThreadId #-}
src/UnliftIO/Exception.hs view
@@ -94,7 +94,7 @@ import GHC.Stack.Types (HasCallStack, CallStack, getCallStack) #endif --- | Unlifted 'EUnsafe.catch', but will not catch asynchronous exceptions+-- | Unlifted 'EUnsafe.catch', but will not catch asynchronous exceptions. -- -- @since 0.1.0.0 catch :: (MonadUnliftIO m, Exception e) => m a -> (e -> m a) -> m a@@ -105,13 +105,13 @@     -- since we want to preserve async behavior     else EUnsafe.throwIO e --- | 'catch' specialized to only catching 'IOException's+-- | 'catch' specialized to only catching 'IOException's. -- -- @since 0.1.0.0 catchIO :: MonadUnliftIO m => m a -> (IOException -> m a) -> m a catchIO = catch --- | 'catch' specialized to catch all synchronous exception+-- | 'catch' specialized to catch all synchronous exception. -- -- @since 0.1.0.0 catchAny :: MonadUnliftIO m => m a -> (SomeException -> m a) -> m a@@ -125,9 +125,9 @@           => m a -> (e -> m a) -> m a catchDeep m = catch (m >>= evaluateDeep) --- | 'catchDeep' specialized to catch all synchronous exception+-- | 'catchDeep' specialized to catch all synchronous exception. ----- @since 0.1.1.0+-- @since 0.1.0.0 catchAnyDeep :: (NFData a, MonadUnliftIO m) => m a -> (SomeException -> m a) -> m a catchAnyDeep = catchDeep @@ -139,31 +139,31 @@ catchJust :: (MonadUnliftIO m, Exception e) => (e -> Maybe b) -> m a -> (b -> m a) -> m a catchJust f a b = a `catch` \e -> maybe (liftIO (throwIO e)) b $ f e --- | Flipped version of 'catch'+-- | Flipped version of 'catch'. -- -- @since 0.1.0.0 handle :: (MonadUnliftIO m, Exception e) => (e -> m a) -> m a -> m a handle = flip catch --- | 'C.handle' specialized to only catching 'IOException's+-- | 'handle' specialized to only catching 'IOException's. -- -- @since 0.1.0.0 handleIO :: MonadUnliftIO m => (IOException -> m a) -> m a -> m a handleIO = handle --- | Flipped version of 'catchAny'+-- | Flipped version of 'catchAny'. -- -- @since 0.1.0.0 handleAny :: MonadUnliftIO m => (SomeException -> m a) -> m a -> m a handleAny = handle --- | Flipped version of 'catchDeep'+-- | Flipped version of 'catchDeep'. ----- @since 0.1.1.0+-- @since 0.1.0.0 handleDeep :: (MonadUnliftIO m, Exception e, NFData a) => (e -> m a) -> m a -> m a handleDeep = flip catchDeep --- | Flipped version of 'catchAnyDeep'+-- | Flipped version of 'catchAnyDeep'. -- -- @since 0.1.0.0 handleAnyDeep :: (MonadUnliftIO m, NFData a) => (SomeException -> m a) -> m a -> m a@@ -175,19 +175,19 @@ handleJust :: (MonadUnliftIO m, Exception e) => (e -> Maybe b) -> (b -> m a) -> m a -> m a handleJust f = flip (catchJust f) --- | Unlifted 'EUnsafe.try', but will not catch asynchronous exceptions+-- | Unlifted 'EUnsafe.try', but will not catch asynchronous exceptions. -- -- @since 0.1.0.0 try :: (MonadUnliftIO m, Exception e) => m a -> m (Either e a) try f = catch (liftM Right f) (return . Left) --- | 'try' specialized to only catching 'IOException's+-- | 'try' specialized to only catching 'IOException's. -- -- @since 0.1.0.0 tryIO :: MonadUnliftIO m => m a -> m (Either IOException a) tryIO = try --- | 'try' specialized to catch all synchronous exceptions+-- | 'try' specialized to catch all synchronous exceptions. -- -- @since 0.1.0.0 tryAny :: MonadUnliftIO m => m a -> m (Either SomeException a)@@ -200,9 +200,9 @@ tryDeep :: (MonadUnliftIO m, Exception e, NFData a) => m a -> m (Either e a) tryDeep f = catch (liftM Right (f >>= evaluateDeep)) (return . Left) --- | 'tryDeep' specialized to catch all synchronous exceptions+-- | 'tryDeep' specialized to catch all synchronous exceptions. ----- @since 0.1.1.0+-- @since 0.1.0.0 tryAnyDeep :: (MonadUnliftIO m, NFData a) => m a -> m (Either SomeException a) tryAnyDeep = tryDeep @@ -213,12 +213,12 @@ tryJust :: (MonadUnliftIO m, Exception e) => (e -> Maybe b) -> m a -> m (Either b a) tryJust f a = catch (Right `liftM` a) (\e -> maybe (throwIO e) (return . Left) (f e)) --- | Generalized version of 'EUnsafe.Handler'+-- | Generalized version of 'EUnsafe.Handler'. -- -- @since 0.1.0.0 data Handler m a = forall e . Exception e => Handler (e -> m a) --- | Internal+-- | Internal. catchesHandler :: MonadIO m => [Handler m a] -> SomeException -> m a catchesHandler handlers e = foldr tryHandler (liftIO (EUnsafe.throwIO e)) handlers     where tryHandler (Handler handler) res@@ -227,7 +227,7 @@                 Nothing -> res  -- | Same as upstream 'EUnsafe.catches', but will not catch--- asynchronous exceptions+-- asynchronous exceptions. -- -- @since 0.1.0.0 catches :: MonadUnliftIO m => m a -> [Handler m a] -> m a@@ -240,7 +240,9 @@ catchesDeep :: (MonadUnliftIO m, NFData a) => m a -> [Handler m a] -> m a catchesDeep io handlers = (io >>= evaluateDeep) `catch` catchesHandler handlers --- | Lifted version of 'EUnsafe.evaluate'+-- | Lifted version of 'EUnsafe.evaluate'.+--+-- @since 0.1.0.0 evaluate :: MonadIO m => a -> m a evaluate = liftIO . EUnsafe.evaluate @@ -250,7 +252,7 @@ evaluateDeep :: (MonadIO m, NFData a) => a -> m a evaluateDeep = (evaluate $!!) --- | Async safe version of 'EUnsafe.bracket'+-- | Async safe version of 'EUnsafe.bracket'. -- -- @since 0.1.0.0 bracket :: MonadUnliftIO m => m a -> (a -> m b) -> (a -> m c) -> m c@@ -271,13 +273,13 @@       _ <- EUnsafe.uninterruptibleMask_ $ unliftIO u $ after x       return y --- | Async safe version of 'EUnsafe.bracket_'+-- | Async safe version of 'EUnsafe.bracket_'. -- -- @since 0.1.0.0 bracket_ :: MonadUnliftIO m => m a -> m b -> m c -> m c bracket_ before after thing = bracket before (const after) (const thing) --- | Async safe version of 'EUnsafe.bracketOnError'+-- | Async safe version of 'EUnsafe.bracketOnError'. -- -- @since 0.1.0.0 bracketOnError :: MonadUnliftIO m => m a -> (a -> m b) -> (a -> m c) -> m c@@ -299,7 +301,7 @@ bracketOnError_ :: MonadUnliftIO m => m a -> m b -> m c -> m c bracketOnError_ before after thing = bracketOnError before (const after) (const thing) --- | Async safe version of 'EUnsafe.finally'+-- | Async safe version of 'EUnsafe.finally'. -- -- @since 0.1.0.0 finally :: MonadUnliftIO m => m a -> m b -> m a@@ -329,38 +331,40 @@             EUnsafe.throwIO e1         Right x -> return x --- | Async safe version of 'EUnsafe.onException'+-- | Async safe version of 'EUnsafe.onException'. -- -- @since 0.1.0.0 onException :: MonadUnliftIO m => m a -> m b -> m a onException thing after = withException thing (\(_ :: SomeException) -> after) --- | Synchronously throw the given exception+-- | Synchronously throw the given exception. -- -- @since 0.1.0.0 throwIO :: (MonadIO m, Exception e) => e -> m a throwIO = liftIO . EUnsafe.throwIO . toSyncException  -- | Wrap up an asynchronous exception to be treated as a synchronous--- exception+-- exception. ----- This is intended to be created via 'toSyncException'+-- This is intended to be created via 'toSyncException'. -- -- @since 0.1.0.0 data SyncExceptionWrapper = forall e. Exception e => SyncExceptionWrapper e     deriving Typeable+-- | @since 0.1.0.0 instance Show SyncExceptionWrapper where     show (SyncExceptionWrapper e) = show e+-- | @since 0.1.0.0 instance Exception SyncExceptionWrapper where #if MIN_VERSION_base(4,8,0)     displayException (SyncExceptionWrapper e) = displayException e #endif --- | Convert an exception into a synchronous exception+-- | Convert an exception into a synchronous exception. -- -- For synchronous exceptions, this is the same as 'toException'. -- For asynchronous exceptions, this will wrap up the exception with--- 'SyncExceptionWrapper'+-- 'SyncExceptionWrapper'. -- -- @since 0.1.0.0 toSyncException :: Exception e => e -> SomeException@@ -372,15 +376,17 @@     se = toException e  -- | Wrap up a synchronous exception to be treated as an asynchronous--- exception+-- exception. ----- This is intended to be created via 'toAsyncException'+-- This is intended to be created via 'toAsyncException'. -- -- @since 0.1.0.0 data AsyncExceptionWrapper = forall e. Exception e => AsyncExceptionWrapper e     deriving Typeable+-- | @since 0.1.0.0 instance Show AsyncExceptionWrapper where     show (AsyncExceptionWrapper e) = show e+-- | @since 0.1.0.0 instance Exception AsyncExceptionWrapper where     toException = toException . SomeAsyncException     fromException se = do@@ -390,11 +396,11 @@     displayException (AsyncExceptionWrapper e) = displayException e #endif --- | Convert an exception into an asynchronous exception+-- | Convert an exception into an asynchronous exception. -- -- For asynchronous exceptions, this is the same as 'toException'. -- For synchronous exceptions, this will wrap up the exception with--- 'AsyncExceptionWrapper'+-- 'AsyncExceptionWrapper'. -- -- @since 0.1.0.0 toAsyncException :: Exception e => e -> SomeException@@ -405,7 +411,7 @@   where     se = toException e --- | Check if the given exception is synchronous+-- | Check if the given exception is synchronous. -- -- @since 0.1.0.0 isSyncException :: Exception e => e -> Bool@@ -414,7 +420,7 @@         Just (SomeAsyncException _) -> False         Nothing -> True --- | Check if the given exception is asynchronous+-- | Check if the given exception is asynchronous. -- -- @since 0.1.0.0 isAsyncException :: Exception e => e -> Bool@@ -424,34 +430,37 @@ #if !MIN_VERSION_base(4,8,0) -- | A synonym for 'show', specialized to 'Exception' instances. ----- Starting with base 4.8, the 'Exception' typeclass has a method @displayException@, used for user-friendly display of exceptions. This function provides backwards compatibility for users on base 4.7 and earlier, so that anyone importing this module can simply use @displayException@.+-- Starting with base 4.8, the 'Exception' typeclass has a method+-- @displayException@, used for user-friendly display of exceptions.+-- This function provides backwards compatibility for users on base 4.7 and earlier,+-- so that anyone importing this module can simply use @displayException@. -- -- @since 0.1.0.0 displayException :: Exception e => e -> String displayException = show #endif --- | Unlifted version of 'EUnsafe.mask'+-- | Unlifted version of 'EUnsafe.mask'. -- -- @since 0.1.0.0 mask :: MonadUnliftIO m => ((forall a. m a -> m a) -> m b) -> m b mask f = withUnliftIO $ \u -> EUnsafe.mask $ \unmask ->   unliftIO u $ f $ liftIO . unmask . unliftIO u --- | Unlifted version of 'EUnsafe.uninterruptibleMask'+-- | Unlifted version of 'EUnsafe.uninterruptibleMask'. -- -- @since 0.1.0.0 uninterruptibleMask :: MonadUnliftIO m => ((forall a. m a -> m a) -> m b) -> m b uninterruptibleMask f = withUnliftIO $ \u -> EUnsafe.uninterruptibleMask $ \unmask ->   unliftIO u $ f $ liftIO . unmask . unliftIO u --- | Unlifted version of 'EUnsafe.mask_'+-- | Unlifted version of 'EUnsafe.mask_'. -- -- @since 0.1.0.0 mask_ :: MonadUnliftIO m => m a -> m a mask_ f = withRunInIO $ \run -> EUnsafe.mask_ (run f) --- | Unlifted version of 'EUnsafe.uninterruptibleMask_'+-- | Unlifted version of 'EUnsafe.uninterruptibleMask_'. -- -- @since 0.1.0.0 uninterruptibleMask_ :: MonadUnliftIO m => m a -> m a@@ -494,11 +503,12 @@ -- support call stacks, and the field is simply unit (provided to make -- pattern matching across GHC versions easier). ----- @since 0.1.5.0+-- @since 0.1.0.0 #if MIN_VERSION_base(4,9,0) data StringException = StringException String CallStack   deriving Typeable +-- | @since 0.1.0.0 instance Show StringException where     show (StringException s cs) = concat         $ "Control.Exception.Safe.throwString called with:\n\n"@@ -517,29 +527,32 @@ data StringException = StringException String ()   deriving Typeable +-- | @since 0.1.0.0 instance Show StringException where     show (StringException s _) = "Control.Exception.Safe.throwString called with:\n\n" ++ s #endif++-- | @since 0.1.0.0 instance Exception StringException  -- | Throw an asynchronous exception to another thread. -- -- Synchronously typed exceptions will be wrapped into an -- `AsyncExceptionWrapper`, see--- <https://github.com/fpco/safe-exceptions#determining-sync-vs-async>+-- <https://github.com/fpco/safe-exceptions#determining-sync-vs-async>. ----- It's usually a better idea to use the async package, see--- <https://github.com/fpco/safe-exceptions#quickstart>+-- It's usually a better idea to use the "UnliftIO.Async" module, see+-- <https://github.com/fpco/safe-exceptions#quickstart>. -- -- @since 0.1.0.0 throwTo :: (Exception e, MonadIO m) => ThreadId -> e -> m () throwTo tid = liftIO . EUnsafe.throwTo tid . toAsyncException  -- | Generate a pure value which, when forced, will synchronously--- throw the given exception+-- throw the given exception. ----- Generally it's better to avoid using this function and instead use 'throw',--- see <https://github.com/fpco/safe-exceptions#quickstart>+-- Generally it's better to avoid using this function and instead use 'throwIO',+-- see <https://github.com/fpco/safe-exceptions#quickstart>. -- -- @since 0.1.0.0 impureThrow :: Exception e => e -> a
src/UnliftIO/IO.hs view
@@ -1,4 +1,4 @@--- | Unlifted "System.IO"+-- | Unlifted "System.IO". -- -- @since 0.1.0.0 module UnliftIO.IO@@ -12,10 +12,14 @@ import System.IO (Handle, IOMode (..)) import Control.Monad.IO.Unlift --- | @since 0.1.0.0+-- | Unlifted version of 'IO.withFile'.+--+-- @since 0.1.0.0 withFile :: MonadUnliftIO m => FilePath -> IOMode -> (Handle -> m a) -> m a withFile fp mode inner = withRunInIO $ \run -> IO.withFile fp mode $ run . inner --- | @since 0.1.0.0+-- | Unlifted version of 'IO.withBinaryFile'.+--+-- @since 0.1.0.0 withBinaryFile :: MonadUnliftIO m => FilePath -> IOMode -> (Handle -> m a) -> m a withBinaryFile fp mode inner = withRunInIO $ \run -> IO.withBinaryFile fp mode $ run . inner
src/UnliftIO/IORef.hs view
@@ -1,4 +1,4 @@--- | Unlifted "Data.IORef"+-- | Unlifted "Data.IORef". -- -- @since 0.1.0.0 module UnliftIO.IORef@@ -19,55 +19,55 @@ import Control.Monad.IO.Unlift import System.Mem.Weak (Weak) --- | Lifted 'I.newIORef'+-- | Lifted 'I.newIORef'. -- -- @since 0.1.0.0 newIORef :: MonadIO m => a -> m (IORef a) newIORef = liftIO . I.newIORef --- | Lifted 'I.readIORef'+-- | Lifted 'I.readIORef'. -- -- @since 0.1.0.0 readIORef :: MonadIO m => IORef a -> m a readIORef = liftIO . I.readIORef --- | Lifted 'I.writeIORef'+-- | Lifted 'I.writeIORef'. -- -- @since 0.1.0.0 writeIORef :: MonadIO m => IORef a -> a -> m () writeIORef ref = liftIO . I.writeIORef ref --- | Lifted 'I.modifyIORef'+-- | Lifted 'I.modifyIORef'. -- -- @since 0.1.0.0 modifyIORef :: MonadIO m => IORef a -> (a -> a) -> m () modifyIORef ref = liftIO . I.modifyIORef ref --- | Lifted 'I.modifyIORef''+-- | Lifted 'I.modifyIORef''. -- -- @since 0.1.0.0 modifyIORef' :: MonadIO m => IORef a -> (a -> a) -> m () modifyIORef' ref = liftIO . I.modifyIORef' ref --- | Lifted 'I.atomicModifyIORef'+-- | Lifted 'I.atomicModifyIORef'. -- -- @since 0.1.0.0 atomicModifyIORef :: MonadIO m => IORef a -> (a -> (a, b)) -> m b atomicModifyIORef ref = liftIO . I.atomicModifyIORef ref --- | Lifted 'I.atomicModifyIORef''+-- | Lifted 'I.atomicModifyIORef''. -- -- @since 0.1.0.0 atomicModifyIORef' :: MonadIO m => IORef a -> (a -> (a, b)) -> m b atomicModifyIORef' ref = liftIO . I.atomicModifyIORef' ref --- | Lifted 'I.atomicWriteIORef'+-- | Lifted 'I.atomicWriteIORef'. -- -- @since 0.1.0.0 atomicWriteIORef :: MonadIO m => IORef a -> a -> m () atomicWriteIORef ref = liftIO . I.atomicWriteIORef ref --- | Unlifted 'I.mkWeakIORef'+-- | Unlifted 'I.mkWeakIORef'. -- -- @since 0.1.0.0 mkWeakIORef :: MonadUnliftIO m => IORef a -> m () -> m (Weak (IORef a))
src/UnliftIO/Instances.hs view
@@ -1,4 +1,4 @@--- | Orphans instances+-- | Orphans instances. -- -- @since 0.1.0.0 module UnliftIO.Instances () where@@ -7,14 +7,19 @@ import Control.Monad.Logger (LoggingT (..), NoLoggingT (..)) -- FIXME move these instances into monad-logger import Control.Monad.Trans.Resource.Internal (ResourceT (..)) +-- | @since 0.1.0.0 instance MonadUnliftIO m => MonadUnliftIO (LoggingT m) where   askUnliftIO = LoggingT $ \f ->                 withUnliftIO $ \u ->                 return (UnliftIO (unliftIO u . flip runLoggingT f))++-- | @since 0.1.0.0 instance MonadUnliftIO m => MonadUnliftIO (NoLoggingT m) where   askUnliftIO = NoLoggingT $                 withUnliftIO $ \u ->                 return (UnliftIO (unliftIO u . runNoLoggingT))++-- | @since 0.1.0.0 instance MonadUnliftIO m => MonadUnliftIO (ResourceT m) where   askUnliftIO = ResourceT $ \r ->                 withUnliftIO $ \u ->
src/UnliftIO/MVar.hs view
@@ -1,4 +1,4 @@--- | Unlifted "Control.Concurrent.MVar"+-- | Unlifted "Control.Concurrent.MVar". -- -- @since 0.1.0.0 module UnliftIO.MVar@@ -27,103 +27,103 @@ import Control.Monad.IO.Unlift import qualified Control.Concurrent.MVar as M --- | Lifted 'M.newEmptyMVar'+-- | Lifted 'M.newEmptyMVar'. -- -- @since 0.1.0.0 newEmptyMVar :: MonadIO m => m (MVar a) newEmptyMVar = liftIO M.newEmptyMVar --- | Lifted 'M.newMVar'+-- | Lifted 'M.newMVar'. -- -- @since 0.1.0.0 newMVar :: MonadIO m => a -> m (MVar a) newMVar = liftIO . M.newMVar --- | Lifted 'M.takeMVar'+-- | Lifted 'M.takeMVar'. -- -- @since 0.1.0.0 takeMVar :: MonadIO m => MVar a -> m a takeMVar = liftIO . M.takeMVar --- | Lifted 'M.putMVar'+-- | Lifted 'M.putMVar'. -- -- @since 0.1.0.0 putMVar :: MonadIO m => MVar a -> a -> m () putMVar var = liftIO . M.putMVar var --- | Lifted 'M.readMVar'+-- | Lifted 'M.readMVar'. -- -- @since 0.1.0.0 readMVar :: MonadIO m => MVar a -> m a readMVar = liftIO . M.readMVar --- | Lifted 'M.swapMVar'+-- | Lifted 'M.swapMVar'. -- -- @since 0.1.0.0 swapMVar :: MonadIO m => MVar a -> a -> m a swapMVar var = liftIO . M.swapMVar var --- | Lifted 'M.tryTakeMVar'+-- | Lifted 'M.tryTakeMVar'. -- -- @since 0.1.0.0 tryTakeMVar :: MonadIO m => MVar a -> m (Maybe a) tryTakeMVar = liftIO . M.tryTakeMVar --- | Lifted 'M.tryPutMVar'+-- | Lifted 'M.tryPutMVar'. -- -- @since 0.1.0.0 tryPutMVar :: MonadIO m => MVar a -> a -> m Bool tryPutMVar var = liftIO . M.tryPutMVar var --- | Lifted 'M.isEmptyMVar'+-- | Lifted 'M.isEmptyMVar'. -- -- @since 0.1.0.0 isEmptyMVar :: MonadIO m => MVar a -> m Bool isEmptyMVar = liftIO . M.isEmptyMVar --- | Lifted 'M.tryReadMVar'+-- | Lifted 'M.tryReadMVar'. -- -- @since 0.1.0.0 tryReadMVar :: MonadIO m => MVar a -> m (Maybe a) tryReadMVar = liftIO . M.tryReadMVar --- | Unlifted 'M.withMVar'+-- | Unlifted 'M.withMVar'. -- -- @since 0.1.0.0 withMVar :: MonadUnliftIO m => MVar a -> (a -> m b) -> m b withMVar var f = withRunInIO $ \run -> M.withMVar var (run . f) --- | Unlifted 'M.withMVarMasked'+-- | Unlifted 'M.withMVarMasked'. -- -- @since 0.1.0.0 withMVarMasked :: MonadUnliftIO m => MVar a -> (a -> m b) -> m b withMVarMasked var f = withRunInIO $ \run -> M.withMVarMasked var (run . f) --- | Unlifted 'M.modifyMVar_'+-- | Unlifted 'M.modifyMVar_'. -- -- @since 0.1.0.0 modifyMVar_ :: MonadUnliftIO m => MVar a -> (a -> m a) -> m () modifyMVar_ var f = withRunInIO $ \run -> M.modifyMVar_ var (run . f) --- | Unlifted 'M.modifyMVar'+-- | Unlifted 'M.modifyMVar'. -- -- @since 0.1.0.0 modifyMVar :: MonadUnliftIO m => MVar a -> (a -> m (a, b)) -> m b modifyMVar var f = withRunInIO $ \run -> M.modifyMVar var (run . f) --- | Unlifted 'M.modifyMVarMasked_'+-- | Unlifted 'M.modifyMVarMasked_'. -- -- @since 0.1.0.0 modifyMVarMasked_ :: MonadUnliftIO m => MVar a -> (a -> m a) -> m () modifyMVarMasked_ var f = withRunInIO $ \run -> M.modifyMVarMasked_ var (run . f) --- | Unlifted 'M.modifyMVarMasked'+-- | Unlifted 'M.modifyMVarMasked'. -- -- @since 0.1.0.0 modifyMVarMasked :: MonadUnliftIO m => MVar a -> (a -> m (a, b)) -> m b modifyMVarMasked var f = withRunInIO $ \run -> M.modifyMVarMasked var (run . f) --- | Unlifted 'M.mkWeakMVar'+-- | Unlifted 'M.mkWeakMVar'. -- -- @since 0.1.0.0 mkWeakMVar :: MonadUnliftIO m => MVar a -> m () -> m (Weak (MVar a))
src/UnliftIO/Resource.hs view
@@ -1,4 +1,4 @@--- | Unlifted "Control.Monad.Trans.Resource"+-- | Unlifted "Control.Monad.Trans.Resource". -- -- @since 0.1.0.0 module UnliftIO.Resource@@ -15,10 +15,14 @@ import Control.Monad.IO.Unlift import UnliftIO.Instances () --- | @since 0.1.0.0+-- | Unlifted version of 'Res.runResourceT'.+--+-- @since 0.1.0.0 runResourceT :: MonadUnliftIO m => ResourceT m a -> m a runResourceT m = withRunInIO $ \run -> Res.runResourceT $ Res.transResourceT run m --- | @since 0.1.0.0-liftResourceT :: MonadIO m => ResourceT IO a -> Res.ResourceT m a+-- | Lifted version of 'Res.liftResourceT'.+--+-- @since 0.1.0.0+liftResourceT :: MonadIO m => ResourceT IO a -> ResourceT m a liftResourceT (ResourceT f) = ResourceT $ liftIO . f
src/UnliftIO/Temporary.hs view
@@ -1,7 +1,7 @@ {-# LANGUAgE CPP #-}--- | Temporary file and directory support+-- | Temporary file and directory support. ----- Strongly inspired by/stolen from the temporary package+-- Strongly inspired by\/stolen from the <https://github.com/feuerbach/temporary> package. -- -- @since 0.1.0.0 module UnliftIO.Temporary@@ -46,7 +46,7 @@ -- @since 0.1.0.0 withSystemTempDirectory :: MonadUnliftIO m =>                            String   -- ^ Directory name template. See 'openTempFile'.-                        -> (FilePath -> m a) -- ^ Callback that can use the directory+                        -> (FilePath -> m a) -- ^ Callback that can use the directory.                         -> m a withSystemTempDirectory template action = liftIO getCanonicalTemporaryDirectory >>= \tmpDir -> withTempDirectory tmpDir template action @@ -63,9 +63,9 @@ -- -- @since 0.1.0.0 withTempFile :: MonadUnliftIO m =>-                FilePath -- ^ Temp dir to create the file in+                FilePath -- ^ Temp dir to create the file in.              -> String   -- ^ File name template. See 'openTempFile'.-             -> (FilePath -> Handle -> m a) -- ^ Callback that can use the file+             -> (FilePath -> Handle -> m a) -- ^ Callback that can use the file.              -> m a withTempFile tmpDir template action =   bracket@@ -85,9 +85,9 @@ -- -- @since 0.1.0.0 withTempDirectory :: MonadUnliftIO m =>-                     FilePath -- ^ Temp directory to create the directory in+                     FilePath -- ^ Temp directory to create the directory in.                   -> String   -- ^ Directory name template. See 'openTempFile'.-                  -> (FilePath -> m a) -- ^ Callback that can use the directory+                  -> (FilePath -> m a) -- ^ Callback that can use the directory.                   -> m a withTempDirectory targetDir template =   bracket@@ -108,8 +108,8 @@  -- | Create a temporary directory. See 'withTempDirectory'. createTempDirectory-  :: FilePath -- ^ Temp directory to create the directory in-  -> String -- ^ Directory name template+  :: FilePath -- ^ Temp directory to create the directory in.+  -> String -- ^ Directory name template.   -> IO FilePath createTempDirectory dir template = do   pid <- c_getpid
src/UnliftIO/Timeout.hs view
@@ -1,4 +1,4 @@--- | Unlifted "System.Timeout"+-- | Unlifted "System.Timeout". -- -- @since 0.1.0.0 module UnliftIO.Timeout@@ -8,7 +8,7 @@ import qualified System.Timeout as S import Control.Monad.IO.Unlift --- | Unlifted 'S.timeout'+-- | Unlifted 'S.timeout'. -- -- @since 0.1.0.0 timeout :: MonadUnliftIO m => Int -> m a -> m (Maybe a)
unliftio.cabal view
@@ -1,13 +1,13 @@--- This file has been generated from package.yaml by hpack version 0.17.0.+-- This file has been generated from package.yaml by hpack version 0.18.1. -- -- see: https://github.com/sol/hpack  name:           unliftio-version:        0.1.0.0+version:        0.1.1.0 synopsis:       The MonadUnliftIO typeclass for unlifting monads to IO (batteries included)-description:    Please see the README.md file for details+description:    Please see the README.md file for details. category:       Control-homepage:       https://github.com/fpco/monad-unlift/tree/master/unliftio#readme+homepage:       https://github.com/fpco/unliftio/tree/master/unliftio#readme author:         Michael Snoyman, Francesco Mazzoli maintainer:     michael@snoyman.com copyright:      2017 FP Complete@@ -40,6 +40,7 @@       UnliftIO       UnliftIO.Async       UnliftIO.Chan+      UnliftIO.Concurrent       UnliftIO.Exception       UnliftIO.IO       UnliftIO.IORef