Class: Ztimer::Watcher
- Inherits:
-
Object
- Object
- Ztimer::Watcher
- Defined in:
- lib/ztimer/watcher.rb
Overview
Implements a watcher which allows to enqueue Ztimer::Slot items, that will be executed as soon as the time of Ztimer::Slot is reached.
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.
7 8 9 10 11 12 13 |
# File 'lib/ztimer/watcher.rb', line 7 def initialize(&callback) @thread = nil @slots = Ztimer::SortedStore.new @callback = callback @lock = Mutex.new @mutex = Mutex.new end |
Instance Method Details
#<<(slot) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/ztimer/watcher.rb', line 15 def <<(slot) @mutex.synchronize do @slots << slot run if @slots.first == slot end end |
#jobs ⇒ Object
22 23 24 |
# File 'lib/ztimer/watcher.rb', line 22 def jobs @slots.size end |