async-extras 0.1.2.0 → 0.1.3.1
raw patch · 3 files changed
+16/−24 lines, 3 filesnew-uploaderPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Control.Concurrent.Async.Extra: instance Alternative Promise
- Control.Concurrent.Async.Extra: instance Applicative Promise
- Control.Concurrent.Async.Extra: instance Functor Promise
- Control.Concurrent.Async.Extra: instance Monad Promise
- Control.Concurrent.Async.Extra: instance MonadPlus Promise
- Control.Concurrent.Async.Extra: unPromise :: Promise a -> IO a
- Control.Concurrent.Async.Lifted.Extra: Promise :: m a -> Promise m a
- Control.Concurrent.Async.Lifted.Extra: instance (b ~ IO, Functor m) => Functor (Promise b m)
- Control.Concurrent.Async.Lifted.Extra: instance (b ~ IO, MonadBaseControl b m) => Alternative (Promise b m)
- Control.Concurrent.Async.Lifted.Extra: instance (b ~ IO, MonadBaseControl b m) => Applicative (Promise b m)
- Control.Concurrent.Async.Lifted.Extra: instance (b ~ IO, MonadBaseControl b m) => Monad (Promise b m)
- Control.Concurrent.Async.Lifted.Extra: instance (b ~ IO, MonadBaseControl b m) => MonadPlus (Promise b m)
- Control.Concurrent.Async.Lifted.Extra: newtype Promise (b :: * -> *) m a
- Control.Concurrent.Async.Lifted.Extra: unPromise :: Promise m a -> m a
+ Control.Concurrent.Async.Extra: [unPromise] :: Promise a -> IO a
+ Control.Concurrent.Async.Extra: forConcurrently_ :: Foldable t => t a -> (a -> IO b) -> IO ()
+ Control.Concurrent.Async.Extra: instance GHC.Base.Alternative Control.Concurrent.Async.Extra.Promise
+ Control.Concurrent.Async.Extra: instance GHC.Base.Applicative Control.Concurrent.Async.Extra.Promise
+ Control.Concurrent.Async.Extra: instance GHC.Base.Functor Control.Concurrent.Async.Extra.Promise
+ Control.Concurrent.Async.Extra: instance GHC.Base.Monad Control.Concurrent.Async.Extra.Promise
+ Control.Concurrent.Async.Extra: instance GHC.Base.MonadPlus Control.Concurrent.Async.Extra.Promise
+ Control.Concurrent.Async.Extra: mapConcurrently_ :: Foldable t => (a -> IO b) -> t a -> IO ()
+ Control.Concurrent.Async.Lifted.Extra: forConcurrently_ :: (Foldable t, MonadBaseControl IO m) => t a -> (a -> m b) -> m ()
+ Control.Concurrent.Async.Lifted.Extra: mapConcurrently_ :: (Foldable t, MonadBaseControl IO m) => (a -> m b) -> t a -> m ()
- Control.Concurrent.Async.Lifted.Extra: withParent :: MonadBaseControl IO m => Async (StM m a) -> m b -> m (Async (StM m b))
+ Control.Concurrent.Async.Lifted.Extra: withParent :: MonadBaseControl IO m => Async a -> m b -> m (Async (StM m b))
Files
- async-extras.cabal +1/−1
- src/Control/Concurrent/Async/Extra.hs +7/−0
- src/Control/Concurrent/Async/Lifted/Extra.hs +8/−23
async-extras.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: async-extras-version: 0.1.2.0+version: 0.1.3.1 synopsis: Extra Utilities for the Async Library -- description: homepage: http://github.com/jfischoff/async-extras
src/Control/Concurrent/Async/Extra.hs view
@@ -7,6 +7,7 @@ import Control.Concurrent import Control.Concurrent.MSem (new, with) import Data.Traversable +import Data.Foldable (Foldable, traverse_) import Control.Applicative import Control.Monad @@ -26,6 +27,12 @@ sequenceConcurrently :: Traversable t => t (IO a) -> IO (t a) sequenceConcurrently = runConcurrently . traverse Concurrently++mapConcurrently_ :: Foldable t => (a -> IO b) -> t a -> IO ()+mapConcurrently_ f = runConcurrently . traverse_ (Concurrently . f)++forConcurrently_ :: Foldable t => t a -> (a -> IO b) -> IO ()+forConcurrently_ = flip mapConcurrently_ -- | Create an 'Async' and pass it to itself. fixAsync :: (Async a -> IO a) -> IO (Async a)
src/Control/Concurrent/Async/Lifted/Extra.hs view
@@ -15,6 +15,7 @@ import Control.Monad.Trans.Control import Control.Monad.Fix import Control.Monad.Base+import Data.Foldable (Foldable, traverse_) -- | Implementation derived from Petr Pudlák's answer on StackOverflow -- <http://stackoverflow.com/a/18898822/230050>@@ -39,6 +40,12 @@ => t (m a) -> m (t a) sequenceConcurrently = runConcurrently . traverse Concurrently +mapConcurrently_ :: (Foldable t, MonadBaseControl IO m) => (a -> m b) -> t a -> m ()+mapConcurrently_ f = runConcurrently . traverse_ (Concurrently . f)++forConcurrently_ :: (Foldable t, MonadBaseControl IO m) => t a -> (a -> m b) -> m ()+forConcurrently_ = flip mapConcurrently_+ -- | Create an 'Async' and pass it to itself. fixAsync :: (MonadFix m, MonadBaseControl IO m) => (Async (StM m a) -> m a) -> m (Async (StM m a))@@ -81,28 +88,6 @@ -- | Create an async that is linked to a parent. If the parent -- dies so does this async withParent :: MonadBaseControl IO m - => Async (StM m a) -> m b -> m (Async (StM m b))+ => Async a -> m b -> m (Async (StM m b)) withParent parent act = async $ link parent >> act ---- | 'Promise' is like 'Concurrently' but includes a sequential monad instance-newtype Promise (b :: * -> *) m a = Promise { unPromise :: m a }--instance (b ~ IO, Functor m) => Functor (Promise b m) where- fmap f (Promise a) = Promise $ f <$> a--instance (b ~ IO, MonadBaseControl b m) => Applicative (Promise b m) where- pure = Promise . return- Promise f <*> Promise x = Promise $ uncurry ($) <$> concurrently f x- -instance (b ~ IO, MonadBaseControl b m) => Alternative (Promise b m) where- empty = Promise $ liftBaseWith . const $ forever (threadDelay maxBound)- Promise x <|> Promise y = Promise $ either id id <$> race x y--instance (b ~ IO, MonadBaseControl b m) => Monad (Promise b m) where- return = pure- Promise m >>= f = Promise $ async m >>= wait >>= unPromise . f --instance (b ~ IO, MonadBaseControl b m) => MonadPlus (Promise b m) where- mzero = empty- mplus = (<|>)