Class: Ztimer::Watcher

Inherits:
Object
  • Object
show all
Defined in:
lib/ztimer/watcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(&callback) ⇒ Watcher

Returns a new instance of Watcher.



5
6
7
8
9
10
11
12
13
# File 'lib/ztimer/watcher.rb', line 5

def initialize(&callback)
  @thread   = nil
  @idler    = Lounger.new
  @slots    = Ztimer::SortedStore.new
  @callback = callback
  @lock     = Mutex.new
  @metric   = Hitimes::Metric.new("Notifier")
  @mutex    = Mutex.new
end

Instance Method Details

#<<(slot) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/ztimer/watcher.rb', line 15

def << (slot)
  @mutex.synchronize do
    @slots << slot
    if @slots.first == slot
      run
    end
  end
end

#jobsObject



24
25
26
# File 'lib/ztimer/watcher.rb', line 24

def jobs
  return @slots.size
end