Class: Ztimer::Watcher
- Inherits:
-
Object
- Object
- Ztimer::Watcher
- Defined in:
- lib/ztimer/watcher.rb
Instance Method Summary collapse
- #<<(slot) ⇒ Object
-
#initialize(&callback) ⇒ Watcher
constructor
A new instance of Watcher.
- #jobs ⇒ Object
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 |
#jobs ⇒ Object
22 23 24 |
# File 'lib/ztimer/watcher.rb', line 22 def jobs return @slots.size end |