Class: Watcher
- Inherits:
-
Object
- Object
- Watcher
- Defined in:
- lib/Watcher.rb
Instance Attribute Summary collapse
-
#refresh_queue ⇒ Object
readonly
Returns the value of attribute refresh_queue.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize ⇒ Watcher
constructor
A new instance of Watcher.
- #pause(name) ⇒ Object
- #register(name, &block) ⇒ Object
- #resume(name) ⇒ Object
- #update ⇒ Object
- #wait ⇒ Object
Constructor Details
Instance Attribute Details
#refresh_queue ⇒ Object (readonly)
Returns the value of attribute refresh_queue.
7 8 9 |
# File 'lib/Watcher.rb', line 7 def refresh_queue @refresh_queue end |
Instance Method Details
#[](key) ⇒ Object
20 21 22 |
# File 'lib/Watcher.rb', line 20 def [] key @queues[key] end |
#pause(name) ⇒ Object
27 28 29 |
# File 'lib/Watcher.rb', line 27 def pause name @threads[name].raise "sleep!" end |
#register(name, &block) ⇒ Object
23 24 25 26 |
# File 'lib/Watcher.rb', line 23 def register name, &block q = @queues[name] = ObservedQueue.new(self) @threads[name] = Thread.new q, &block end |
#resume(name) ⇒ Object
30 31 32 |
# File 'lib/Watcher.rb', line 30 def resume name @threads[name].wakeup end |
#update ⇒ Object
14 15 16 |
# File 'lib/Watcher.rb', line 14 def update @queue.push true end |
#wait ⇒ Object
17 18 19 |
# File 'lib/Watcher.rb', line 17 def wait @queue.pop end |