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
# File 'lib/ztimer/watcher.rb', line 5

def initialize(&callback)
  @thread   = nil
  @slots    = Ztimer::SortedStore.new
  @callback = callback
  @lock     = Mutex.new
  @mutex    = Mutex.new
end

Instance Method Details

#<<(slot) ⇒ Object



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

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

#jobsObject



22
23
24
# File 'lib/ztimer/watcher.rb', line 22

def jobs
  return @slots.size
end