stm-actor: A simplistic actor model based on STM

[ control, library, mit ] [ Propose Tags ]

A simplistic actor model based on STM.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 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.3.0.0, 0.3.1.0
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:51Z
Distributions
Downloads 1557 total (39 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2022-01-21 [all 1 reports]

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.