stm-actor: A simplistic actor model based on STM

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

A simplistic actor model based on STM.


[Skip to Readme]

Properties

Versions 0.1.0.0, 0.1.1.0, 0.1.1.1, 0.1.2.1, 0.2.0.0, 0.2.0.1, 0.2.1.0, 0.2.2.0, 0.2.3.0, 0.2.3.1, 0.2.3.2, 0.2.3.2, 0.3.0.0, 0.3.1.0
Change log None available
Dependencies base (>=4.12 && <4.17), mtl (>=1.0), stm (>=2.1), stm-queue (>=0.1), transformers (>=0.2), unliftio-core (>=0.2) [details]
License MIT
Copyright 2020 Samuel Schlesinger
Author Samuel Schlesinger
Maintainer samuel@simspace.com
Category Control
Source repo head: git clone https://github.com/samuelschlesinger/stm-actor
Uploaded by sgschlesinger at 2022-01-21T08:48:19Z

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for stm-actor-0.2.3.2

[back to package description]

stm-actor

Hackage

An implementation of a basic actor model in Haskell. With a very simple API, this is meant to serve as a basis for writing simple, message-passing style of programs. Here is an example using the etcd library.

{-# LANGUAGE BlockArguments, LambdaCase, OverloadedStrings #-}
import Network.Etcd

main :: IO ()
main = do
  client <- createClient ["machine-1", "machine-2", "machine-3"]
  logger <- act do
    receive \changes -> do
      -- we can do arbitrary things here with the reported changes, of course
      liftIO (appendFile "logfile" (show changes))
  watcher <- act do
    link logger
    liftIO $ forever do
      waitClient client "cluster-resources" >>= \case
        Nothing -> pure ()
        Just updatedNode -> atomically (send actor updatedNode)

If you want multi-node actors or you care about throughput, this is not the package for you. The design is optimized to have low latency on message receipt, and to allow for interactions between actors in transactions, using Haskell's software transactional memory.