struct

Crystal::EventLoop::Timers(T)

Inherits Struct / Value / Object

List of Pointer(T) to T structs.

Internally wraps a PointerPairingHeap(T) and thus requires that T implements PointerPairingHeap::Node.

Thread unsafe: parallel accesses must be protected!

NOTE: this is a struct because it only wraps a const pointer to an object allocated in the heap.

Constructors

Instance methods

add(event : Pointer(T)) : Bool

Add a new timer into the list. Returns true if it is the next ready timer.

Source
delete(event : Pointer(T)) : Tuple(Bool, Bool)

Remove a timer from the list. Returns a tuple(dequeued, was_next_ready) of booleans. The first bool tells whether the event was dequeued, in which case the second one tells if it was the next ready event.

Source
dequeue_ready

Dequeues and yields each ready timer (their #wake_at is lower than Crystal::System::Time.instant) from the oldest to the most recent (i.e. time ascending).

Source
empty?
Source
next_ready?

Returns the time of the next ready timer (if any).

Source