poolboy 0.4.1.0 → 0.5.0.0
raw patch · 4 files changed
+26/−10 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Data.Poolboy: isStopedWorkQueue :: MonadUnliftIO m => WorkQueue m -> m Bool
+ Data.Poolboy: hoistPoolboySettings :: (forall a. () => m a -> n a) -> PoolboySettings m -> PoolboySettings n
+ Data.Poolboy: hoistWorkQueue :: (forall a. () => m a -> n a) -> WorkQueue m -> WorkQueue n
+ Data.Poolboy: isStoppedWorkQueue :: MonadIO m => WorkQueue m -> m Bool
- Data.Poolboy: stopWorkQueue :: MonadUnliftIO m => WorkQueue m -> m ()
+ Data.Poolboy: stopWorkQueue :: MonadIO m => WorkQueue m -> m ()
Files
- CHANGELOG.md +5/−0
- poolboy.cabal +2/−2
- src/Data/Poolboy.hs +17/−6
- src/Data/Poolboy/Tactics.hs +2/−2
CHANGELOG.md view
@@ -1,3 +1,8 @@+## 0.5.0.0++* Add helpers on `WorkQueue` and `PoolboySettings` in `Data.Poolboy`+* Rename `isStopedWorkQueue` to `isStoppedWorkQueue` in `Data.Poolboy`+ ## 0.4.1.0 * Add helpers in `Data.Poolboy.Tactics`
poolboy.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: poolboy-version: 0.4.1.0+version: 0.5.0.0 author: Gautier DI FOLCO maintainer: foss@difolco.dev category: Data@@ -10,7 +10,7 @@ synopsis: Simple work queue for bounded concurrency description: In-memory work queue helping with load management. Homepage: https://github.com/blackheaven/poolboy-tested-with: GHC==9.8.4+tested-with: GHC==9.10.3 extra-source-files: CHANGELOG.md
src/Data/Poolboy.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE StrictData #-} {-# LANGUAGE TupleSections #-} --- |@@ -26,11 +27,13 @@ poolboySettingsWith, poolboySettingsName, poolboySettingsLog,+ hoistPoolboySettings, -- * Running WorkQueue, withPoolboy, newPoolboy,+ hoistWorkQueue, -- * Driving changeDesiredWorkersCount,@@ -38,7 +41,7 @@ -- * Stopping stopWorkQueue,- isStopedWorkQueue,+ isStoppedWorkQueue, WaitingStopStrategy, waitingStopTimeout, waitingStopFinishWorkers,@@ -74,6 +77,10 @@ logger :: PoolboyCommand -> m () } +-- | Change 'PoolboySettings' monad+hoistPoolboySettings :: (forall a. m a -> n a) -> PoolboySettings m -> PoolboySettings n+hoistPoolboySettings hoist PoolboySettings {..} = PoolboySettings {logger = hoist . logger, ..}+ -- | Initial number of threads data WorkersCountSettings = -- | 'getNumCapabilities' based number@@ -174,16 +181,16 @@ refWorkers - n -- | Request stopping wokers-stopWorkQueue :: (MonadUnliftIO m) => WorkQueue m -> m ()+stopWorkQueue :: (MonadIO m) => WorkQueue m -> m () stopWorkQueue wq = do- stopped <- isStopedWorkQueue wq+ stopped <- isStoppedWorkQueue wq unless stopped $ do wq.onCommand SetStoppedWorkQueue void $ tryPutMVar wq.stopped () -- | Non-blocking check of the work queue's running status-isStopedWorkQueue :: (MonadUnliftIO m) => WorkQueue m -> m Bool-isStopedWorkQueue wq = not <$> isEmptyMVar wq.stopped+isStoppedWorkQueue :: (MonadIO m) => WorkQueue m -> m Bool+isStoppedWorkQueue wq = not <$> isEmptyMVar wq.stopped type WaitingStopStrategy m = WorkQueue m -> m () @@ -264,12 +271,16 @@ inflightWorkers :: IORef (HM.HashMap ThreadId (Maybe (Async ()))) } +-- | Change 'WorkQueue' monad+hoistWorkQueue :: (forall a. m a -> n a) -> WorkQueue m -> WorkQueue n+hoistWorkQueue hoist WorkQueue {..} = WorkQueue {onCommand = hoist . onCommand, ..}+ -- | Ensure the queue is stopped -- -- Throws 'WorkQueueStoppedException' if not ensureRunning :: (MonadUnliftIO m) => WorkQueue m -> m () ensureRunning wq = do- stopped <- isStopedWorkQueue wq+ stopped <- isStoppedWorkQueue wq threadId <- myThreadId workers <- readIORef wq.inflightWorkers let isRunning = not stopped || HM.member threadId workers
src/Data/Poolboy/Tactics.hs view
@@ -151,10 +151,10 @@ PoolboySettings m -> m (Maybe (m a)) -> m [a]-concurrentM settings actions = do+concurrentM settings fetchNextAction = do accumulator <- newIORef mempty let accumulate action = do result <- action atomicModifyIORef' accumulator $ \acc -> (result : acc, ())- concurrentM_ settings $ fmap accumulate <$> actions+ concurrentM_ settings $ fmap accumulate <$> fetchNextAction readIORef accumulator