Package documentation

tattle

1.0.0

By Peregrine Finch

Tattle

Package Version Hex Docs Tests

Send typed events and measure work using a bus you pass to the code that needs it. Each bus fixes its metadata type. An HTTP service might use a record with a route and request ID, while a worker might use a job name.

Pooka
module main

import tattle.{Phase}

main() {
  let bus = tattle.new().attach("console", ["http"], fn(event) {
    match event.phase {
      Phase.Stop -> {
        echo #(event.name, event.metadata, event.duration_us)
        Nil
      }
      _ -> Nil
    }
  })

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

emit sends an instant event and returns delivered and failed handler counts. span sends a start event followed by a stop or exception event. Its duration uses the monotonic clock in microseconds. The callback's value or exception propagates to the caller.

attach and detach return a new bus. An empty prefix matches all events, and attaching an existing ID replaces that handler. Matching handlers run synchronously in the caller, newest first. Keep them short and hand off slow work to a worker. A handler that raises is counted as failed, and the remaining handlers still run.

Run the suite with pooka test.

Licence

Licensed under the Apache License, Version 2.0.