class Tasker::Reactor

Overview

A single, process-wide timing reactor.

Historically every pending Tasker::Task owned its own fiber that simply slept until the task was due. In a process running many schedules (and one short-lived timeout timer per in-flight queued command) that is thousands of sleeping fibers, each holding a fiber stack. Crystal's fiber stack pool grows to the high-water mark of live fibers and never fully returns it, so a large population of sleeping timer fibers permanently inflates RSS.

The reactor replaces those per-task fibers with a single scheduler fiber that owns an indexed binary min-heap keyed on each task's next fire time. Pending tasks cost a heap entry, not a fiber. When a task is due the reactor spawns a short-lived fiber to run its callback — isolation is preserved (a blocking callback cannot stall the scheduler or sibling tasks), but a fiber only exists while a callback is actually executing.

Defined in:

tasker/reactor.cr

Constant Summary

Log = ::Log.for("tasker.reactor")

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new #

[View source]

Class Method Detail

def self.instance : Tasker::Reactor #

[View source]

Instance Method Detail

def cancel(task : Tasker::Task) : Nil #

Remove task so it will not fire.


[View source]
def schedule(task : Tasker::Task) : Nil #

Register (or re-register) task to fire at its next_scheduled time.


[View source]