Class: Watcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWatcher

Returns a new instance of Watcher.



8
9
10
11
12
13
# File 'lib/Watcher.rb', line 8

def initialize
  @queue = Queue.new
  @queues = {}
  @threads = {}
  @refresh_queue = LastQueue.new
end

Instance Attribute Details

#refresh_queueObject (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

#updateObject



14
15
16
# File 'lib/Watcher.rb', line 14

def update
  @queue.push true
end

#waitObject



17
18
19
# File 'lib/Watcher.rb', line 17

def wait
  @queue.pop
end