locked-poll: Very simple poll lock

[ bsd3, library, program, unclassified ] [ Propose Tags ] [ Report a vulnerability ]

Fire and forget actions, lock with timeout resources


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0
Change log ChangeLog.md
Dependencies base (>=4 && <5), clock, containers, locked-poll [details]
License BSD-3-Clause
Author Scott Murphy <scottmurphy09@gmail.com>
Maintainer Scott Murphy <scottmurphy09@gmail.com>
Source repo head: git clone https://github.com/plow-technologies/locked-poll.git
Uploaded by scottmurphy09 at 2015-12-17T21:15:46Z
Distributions
Executables locked-poll
Downloads 861 total (5 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2015-12-17 [all 1 reports]

Readme for locked-poll-0.1.0

[back to package description]

Circle CI

locked-poll

locked-poll is a package to enable simple concurrent polling with a locking scheme.

The library is quite small, needing

  • containers
  • clock

To run.

There are lots of tests in the test-suite to ensure that it behaves itself with polls.

Usage-Example

There is only one function :


makeLockingFunction :: forall k lockableState . (Key k,Show lockableState) =>
                       Int64 ->  -- timeout
                       (KeyFcn lockableState k) ->          -- extract a key
                       IO ((lockableState -> IO ()) ->      -- function to run against state
                       lockableState   ->                   -- incoming state
                       IO ())

This function is used to generate a function which has an embedded action that is dependent on some given state. The idea is to generate that locking function at the top level and then pass it to whatever needs incremental access to a resource.

It uses an IORef under the hood to store what states are currently in use.

Use the timeout function to say when to release the lock.

No cleanup is performed by the lockingFunction, so wrap your things in finally or bracket as needed.

-- | 'Key' Constraint for locking down a traverse or fold
type Key k = (Ord k,Eq k,Show k)

-- |Extract a key from a given state
type KeyFcn st k = Key k => st -> k

KeyFcn tells the lockingFunction how to extract the LockingKey.

Uniqueness is not necessary but if you do not have it, only one of a given group of like Keyed objects will be allowed to run at a time.

How to run tests

cabal configure --enable-tests && cabal build && cabal test

The tests are quite slow (4 or 5 min) because they are trying to test long poll concurrency

Right now you have to hand delete the resulting output.

Contributing

TODO: Write contribution instructions here