dev-haskell/stm-linkedlist (haskell)

Search

Package Information

Description:
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
Homepage:
https://hackage.haskell.org/package/stm-linkedlist
License:
BSD

Versions

Version EAPI Keywords Slot
0.1.0.0 8 ~amd64 0/0.1.0.0

Metadata

Description

Maintainers

Raw Metadata XML
<pkgmetadata>
	<maintainer type="project">
		<email>haskell@gentoo.org</email>
		<name>Gentoo Haskell</name>
	</maintainer>
	<longdescription>
		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:
		
		&gt;withEventHandler list handler action =
		&gt;    bracket (atomically $ LinkedList.append handler list)
		&gt;            (atomically . LinkedList.delete)
		&gt;            (\_ -&gt; action)
		
		Then, you could have your listener thread dispatch events using a function
		like this:
		
		&gt;dispatchEvent list event = do
		&gt;    handlers &lt;- atomically $ LinkedList.toList list
		&gt;    forM_ handlers $ \handler -&gt; handler event
	</longdescription>
</pkgmetadata>

Lint Warnings

Manifest

Type File Size Versions
DIST stm-linkedlist-0.1.0.0.tar.gz 6143 bytes 0.1.0.0
Unmatched Entries
Type File Size