@hackage batch0.1.0.0
Simplify queuing up data and processing it in batch.
Categories
License
BSD-3-Clause
Maintainer
mail@athiemann.net
Links
Versions
- 0.1.0.0 Sat, 27 Jan 2018
Installation
Dependencies (9)
- async >=2.0
- base >=4.7 && <5
- lifted-async >=0.9
- lifted-base >=0.2.3
- monad-control >=1.0
- mtl >=2.2 Show all…
Dependents (1)
@hackage/acme-everything
batch
Simplify queuing up data and processing it in batch.
import Control.Batch
import Control.Concurrent.STM
import Control.Monad
example :: IO ()
example =
do outVar <- atomically $ newTVar []
let cfg =
Batch
{ b_runEveryItems = Just 5
, b_runAfterTimeout = Nothing
, b_maxQueueLength = Nothing
, b_runBatch =
\x -> atomically $ modifyTVar' outVar (++x)
}
withBatchRunner cfg $ \hdl ->
do replicateM_ 5 $ bh_enqueue hdl True
out <-
atomically $
do x <- readTVar outVar
when (length x /= 5) retry
pure x
out `shouldBe` [True, True, True, True, True]