Module

tattle

src/tattle.pooka

Route typed events through an immutable bus that can be passed to an application, a request handler, or a test.

API reference

enum

Phase

src/tattle.pooka:11
enum Phase

A single event or one of the three steps in a timing span.

variant

Instant

src/tattle.pooka:12
Phase.Instant
variant

Start

src/tattle.pooka:13
Phase.Start
variant

Stop

src/tattle.pooka:14
Phase.Stop
variant

Exception

src/tattle.pooka:15
Phase.Exception
class

Event

src/tattle.pooka:20
class Event(
  name: List(String),
  phase: Phase,
  metadata: a,
  duration_us: Option(Int),
  failure_kind: Option(String)
)

Event names are lists so a handler for ["http"] can receive ["http", "request"]. A span reports duration only when work ends.

field

name

src/tattle.pooka:21
name: List(String)
INFERREDList(String)
field

phase

src/tattle.pooka:22
phase: Phase
INFERREDtattle.Phase
field

metadata

src/tattle.pooka:23
metadata: a
INFERREDa
field

duration_us

src/tattle.pooka:24
duration_us: Option(Int)
INFERREDOption(Int)
field

failure_kind

src/tattle.pooka:25
failure_kind: Option(String)
INFERREDOption(String)
constructor

new

src/tattle.pooka:21
INFERREDfn(List(String), tattle.Phase, a, Option(Int), Option(String)) -> tattle.Event(a)
class

Delivery

src/tattle.pooka:29
class Delivery(delivered: Int, failed: Int)

Counts matching handlers that ran and those that raised.

field

delivered

src/tattle.pooka:29
delivered: Int
INFERREDInt
field

failed

src/tattle.pooka:29
failed: Int
INFERREDInt
constructor

new

src/tattle.pooka:29
INFERREDfn(Int, Int) -> tattle.Delivery
class

Bus

src/tattle.pooka:34
class Bus(a)

A bus fixes one metadata type and keeps its subscriptions with it.

constructor

new

src/tattle.pooka:37
new(handlers: List(_Handler(a)))
INFERREDfn(List(tattle._Handler(a))) -> tattle.Bus(a)
method

attach

src/tattle.pooka:47
attach(id: String, prefix: List(String), callback: fn(Event(a)) -> Nil) -> Bus(
    a
  )
INFERREDfn(String, List(String), fn(tattle.Event(a)) -> Nil) -> tattle.Bus(a)

Return a bus with a handler for the prefix. An empty prefix matches any event. Registering an existing ID replaces that handler.

Pooka
let bus = tattle.new().attach("observer", ["http"], fn(_) { Nil })
method

detach

src/tattle.pooka:56
detach(id: String) -> Bus(a)
INFERREDfn(String) -> tattle.Bus(a)

Return a bus with the named handler removed.

method

dispatch

src/tattle.pooka:62
dispatch(event: Event(a)) -> Delivery
INFERREDfn(tattle.Event(a)) -> tattle.Delivery

Deliver synchronously, newest handler first. Failed handlers are counted and delivery continues to the other matching handlers.

function

new

src/tattle.pooka:92
new() -> Bus(a)
INFERREDfn() -> tattle.Bus(a)

Start with an empty bus. Its metadata type follows from its first use.

Pooka
let bus = tattle.new()
assert tattle.emit(bus, ["worker", "ready"], "mail").delivered == 0
function

emit

src/tattle.pooka:101
emit(bus: Bus(a), name: List(String), metadata: a) -> Delivery
INFERREDfn(tattle.Bus(a), List(String), a) -> tattle.Delivery

Send an instant event and count deliveries.

Pooka
let counts = tattle.emit(bus, ["http", "request"], "/books")
function

span

src/tattle.pooka:112
span(bus: Bus(a), name: List(String), metadata: a, work: fn() -> b) -> b
INFERREDfn(tattle.Bus(a), List(String), a, fn() -> b) -> b

Emit start and stop events around a callback using a monotonic clock. A BEAM exception emits an exception event and propagates to the caller. Handler failures do not change the callback result.

Pooka
let status = tattle.span(bus, ["http", "request"], "/books", fn() { 200 })