concurrent-batch: Concurrent batching queue based on STM with timeout.

[ bsd3, data, library ] [ Propose Tags ]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0
Dependencies base (>=4.7 && <5), clock, stm [details]
License BSD-3-Clause
Copyright 2018 Harpo Roeder
Author Harpo Roeder
Maintainer roederharpo@protonmail.ch
Category Data
Home page https://github.com/harporoeder/concurrent-batch#readme
Bug tracker https://github.com/harporoeder/concurrent-batch/issues
Source repo head: git clone https://github.com/harporoeder/concurrent-batch
Uploaded by HarpoRoeder at 2018-07-28T18:56:25Z
Distributions NixOS:0.1.0.0
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 832 total (14 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2018-07-28 [all 1 reports]

Readme for concurrent-batch-0.1.0.0

[back to package description]

Concurrent STM Batch

This package facilitates batch processing based on STM. Batches are both sized, and have automatic timeout functionality.

Example Usage

The batch handler lives inside STM. Batches should not be processed at this stage but instead pushed somewhere else for processing. In this simple example we store the results in a TMVar and process them with putStrLn. Requiring the initial handler to be in STM instead of IO increases async exception safety without having to mask on a potentially blocked action.

import Control.Concurrent.STM
import Control.Concurrent.STM.TMVar
import Control.Concurrent.STM.Batch

main :: IO ()
main = do
  -- Create variable that batches are pushed to
  output <- newEmptyTMVarIO
  -- Create batches of 3 elements with a timeout of 10 seconds
  batcher <- newBatch 3 (Just $ fromSecs 10) (putTMVar output)
  -- Write 3 items to the batcher
  mapM_ (writeBatch batcher) [1 2 3]
  -- Get the first result batch
  batch1 <- atomically $ takeTMVar output
  -- See [3 2 1]
  putStrLn batch1