Content-Length: 282413 | pFad | https://github.com/plow-technologies/locked-poll.git

14 GitHub - plow-technologies/locked-poll: Very simple locking with timeout for polling functions
Skip to content

plow-technologies/locked-poll

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Very simple locking with timeout for polling functions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/plow-technologies/locked-poll.git

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy