free-agent
Safe HaskellNone
LanguageGHC2024

Free.Agent.Bus.Daemon

Description

The stamping office: a single-writer daemon for the bus.

The bus has two stamping regimes:

  • Office off: writers self-stamp with postLocal — the entangled case, where concurrent writers may race for ids.
  • Office on: writers send bare Post lines to the daemon over a named pipe (root/bus.fifo); the daemon stamps them in arrival order and appends to log.jsonl. This serialisation is the bus's ⅋ discipline made into a process.

The daemon is intentionally stateless: it assigns ids by counting lines in the log under the same exclusive lock that postLocal uses, so the two regimes can coexist during a transition without colliding.

Synopsis

Daemon

runDaemon :: PostBody a => FilePath -> IO () Source #

Run the stamping office forever.

Creates the bus directory, touches log.jsonl, creates the FIFO if absent, then reads one bare Post line at a time. Malformed lines are reported on stderr and skipped; valid lines are stamped and appended.

Client

postViaDaemon :: FilePath -> Post Text -> IO (Stamped Text) Source #

Submit a bare post to the daemon and wait for the receipt.

Paths

fifoPath :: FilePath -> FilePath Source #

Path to the named pipe used to submit bare posts to the daemon.

receiptPath :: FilePath -> Name -> FilePath Source #

Path to the per-sender receipt file. The daemon overwrites this with the latest stamped post from that sender; the client waits for a receipt that matches its submission.