Skip to content

Stats

TypedBus::Stats

Simple counter map for message bus activity. Fiber-safe — no mutex needed within a single Async reactor.

Constructor

Stats.new

Creates a new Stats instance with no counters.

Methods

increment(key)Integer

Increment a named counter. Returns the new value.

stats.increment(:orders_published)  # => 1
stats.increment(:orders_published)  # => 2

[](key)Integer

Read a counter value. Returns 0 for unknown keys.

stats[:orders_published]  # => 2
stats[:nonexistent]       # => 0

reset!

Zero all counters. Keys are preserved, values set to 0.

to_hHash<Symbol, Integer>

Return a snapshot (dup) of all counters.

stats.to_h
# => { orders_published: 2, orders_delivered: 1 }

Attributes

dataHash

Direct access to the underlying counter hash. Prefer [] and to_h for read access.