Typed handlers for a run's events, each registered with its EventType, so that a selection of mixed event types keeps each payload's type:
val handlers = EventHandlers
.on(AgentEvents.TextDelta)(d => print(d.text))
.on(Checked)(c => println(s"checked ${c.path}"))
.otherwise {
case StreamEvent.LiveGap(n) => println(s"[$n live events lost]")
case _ => ()
}
agent.stream(threadId, query)(handlers)
An event is looked up once by its name and version - a durable RunEvent.Custom or a StreamEvent.Live alike - and its payload decoded once, by the one type registered for them. R is what a handler returns: Unit for a listener, or a caller's own type, to turn a run's events into a stream of one ADT (on(Checked)(MyEvent.Checked(_)), the effect modules' events).
An EventHandlers is a listener (StreamEvent => Unit): pass it to Agent.stream, AgentRun.subscribe or GraphRuntime.subscribe. As a listener it runs dispatch and discards the result; a handler that throws is a listener that throws.
The result of the handler for event: the one registered for its name and version, given the decoded payload, or else otherwise's; None when neither takes it.
The result of the handler for event: the one registered for its name and version, given the decoded payload, or else otherwise's; None when neither takes it.
These handlers, with handler for every event no handler takes: a kernel event, a LiveGap, a Disconnected, an event of an unregistered name or version, or a payload that does not decode. Without it those are skipped. It replaces an earlier otherwise.
These handlers, with handler for every event no handler takes: a kernel event, a LiveGap, a Disconnected, an event of an unregistered name or version, or a payload that does not decode. Without it those are skipped. It replaces an earlier otherwise.