Module
tattle
src/tattle.pookaRoute typed events through an immutable bus that can be passed to an application, a request handler, or a test.
API reference
enum Phase
A single event or one of the three steps in a timing span.
Phase.Instant
Phase.Start
Phase.Stop
Phase.Exception
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.
name: List(String)
List(String)phase: Phase
tattle.Phasemetadata: a
aduration_us: Option(Int)
Option(Int)failure_kind: Option(String)
Option(String)
fn(List(String), tattle.Phase, a, Option(Int), Option(String)) -> tattle.Event(a)class Delivery(delivered: Int, failed: Int)
Counts matching handlers that ran and those that raised.
delivered: Int
Intfailed: Int
Int
fn(Int, Int) -> tattle.Deliveryclass Bus(a)
A bus fixes one metadata type and keeps its subscriptions with it.
new(handlers: List(_Handler(a)))
fn(List(tattle._Handler(a))) -> tattle.Bus(a)attach(id: String, prefix: List(String), callback: fn(Event(a)) -> Nil) -> Bus(
a
)
fn(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.
let bus = tattle.new().attach("observer", ["http"], fn(_) { Nil })
detach(id: String) -> Bus(a)
fn(String) -> tattle.Bus(a)Return a bus with the named handler removed.
dispatch(event: Event(a)) -> Delivery
fn(tattle.Event(a)) -> tattle.DeliveryDeliver synchronously, newest handler first. Failed handlers are counted and delivery continues to the other matching handlers.
new() -> Bus(a)
fn() -> tattle.Bus(a)Start with an empty bus. Its metadata type follows from its first use.
let bus = tattle.new()
assert tattle.emit(bus, ["worker", "ready"], "mail").delivered == 0
emit(bus: Bus(a), name: List(String), metadata: a) -> Delivery
fn(tattle.Bus(a), List(String), a) -> tattle.DeliverySend an instant event and count deliveries.
let counts = tattle.emit(bus, ["http", "request"], "/books")
span(bus: Bus(a), name: List(String), metadata: a, work: fn() -> b) -> b
fn(tattle.Bus(a), List(String), a, fn() -> b) -> bEmit 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.
let status = tattle.span(bus, ["http", "request"], "/books", fn() { 200 })