class CQL::Telemetry::EventQueue(T)

Overview

Runs the handler on its own fiber, so #push never waits. Call #close when finished, or that fiber lives forever.

Defined in:

telemetry/event_queue.cr

Constant Summary

MAX_PENDING_FLUSHES = 8

Flushes that may be pending at once, timed-out ones included until the consumer reaches them.

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(capacity : Int32, &handler : T -> ) #

[View source]

Class Method Detail

def self.checked_capacity(capacity : Int32) : Int32 #

capacity itself when a queue can hold that many events; raises ArgumentError otherwise.


[View source]

Instance Method Detail

def close : Nil #

Stops accepting events, then drains the buffer without waiting: events are skipped, flushes return false.


[View source]
def dropped : Int64 #

[View source]
def flush(timeout : Time::Span | Nil = nil) : Bool #

True once every event pushed before it was handled; false on timeout, on close, on the consumer fiber or past MAX_PENDING_FLUSHES. Without a timeout it waits on the handler, even one waiting for the flusher: keep it off hot paths.


[View source]
def push(event : T) : Bool #

Enqueues event without waiting or allocating; false when closed or full (counted in #dropped).


[View source]
def push(& : -> T) : Bool #

Like #push(event), but builds the event only once a slot is free, so a dropped event costs nothing. A block that raises, breaks or returns gives its slot back.


[View source]