The locked-poll package

[Tags:bsd3, library, program, test]

Fire and forget actions, lock with timeout resources


[Skip to Readme]

Properties

Versions 0.1.0
Change log ChangeLog.md
Dependencies base (==4.*), clock, containers, locked-poll [details]
License BSD3
Author Scott Murphy <scottmurphy09@gmail.com>
Maintainer Scott Murphy <scottmurphy09@gmail.com>
Source repository head: git clone https://github.com/plow-technologies/locked-poll.git
Uploaded Thu Dec 17 21:15:46 UTC 2015 by scottmurphy09
Distributions NixOS:0.1.0
Downloads 104 total (11 in the last 30 days)
Votes
0 []
Status Docs available [build log]
Last success reported on 2015-12-17 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Readme for locked-poll

Readme for locked-poll-0.1.0

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