Event Bus
# Event Bus
qti-clockwork-events provides typed buffered and immediate event channels.
Core API
send(event)orsend(type, event)sendImmediate(event)orsendImmediate(type, event)listen(type): Events<T>on(type, listener): unsubscribeclear(type?)
Buffered vs Immediate
sendappends to per-type buffersendImmediateinvokes listeners instantly and does not buffer
Type Inference Rules
Implicit type inference only works for non-primitive class-instance events.
For primitives/plain objects use explicit channel:
events.send(DamageSymbol, { target: 1, amount: 5 })
Clockwork JVM example:
import com.quietterminal.clockwork.ClockworkApp;
record DamageEvent(long target, int amount) {}
ClockworkApp app = new ClockworkApp().build();
app.world().events().subscribe(DamageEvent.class, e ->
System.out.println("damage=" + e.amount() + " target=" + e.target())
);
app.world().events().emit(new DamageEvent(1L, 5));
app.shutdown();
Events Snapshot
Events<T> is immutable for a read call and exposes:
iter()isEmpty()len()