The stm-linkedlist package

[Tags: bsd3, library]

Doubly linked lists are often used in imperative languages to maintain a collection of objects such that an object can remove itself easily. The same idea applies here. Thanks to STM, these lists can be shared among threads with little effort.

Suppose you have a thread listening for events. You want to dispatch events to any thread that opts in. You could write a function that installs an event handler, performs an action, and removes the handler:

withEventHandler list handler action =
    bracket (atomically $ LinkedList.append handler list)
            (atomically . LinkedList.delete)
            (\_ -> action)

Then, you could have your listener thread dispatch events using a function like this:

dispatchEvent list event = do
    handlers <- atomically $ LinkedList.toList list
    forM_ handlers $ \handler -> handler event

Properties

Version0.1.0.0
Dependenciesbase (==4.*), stm
LicenseBSD3
CopyrightCopyright (c) Joseph Adams 2011
AuthorJoey Adams
Maintainerjoeyadams3.14159@gmail.com
CategoryData
Source repositoryhead: git clone git://github.com/joeyadams/haskell-stm-linkedlist.git
Upload dateThu Oct 20 16:57:03 UTC 2011
Uploaded byJoeyAdams
Downloads70 total (8 in last 30 days)

Modules

Downloads

Maintainers' corner

For package maintainers and hackage trustees