Class: Imaginator::Server
- Inherits:
-
Object
- Object
- Imaginator::Server
- Defined in:
- lib/imaginator.rb
Instance Method Summary collapse
- #enqueue(name, type, code) ⇒ Object
- #enqueued?(name) ⇒ Boolean
-
#initialize(renderer) ⇒ Server
constructor
A new instance of Server.
- #run ⇒ Object
Constructor Details
#initialize(renderer) ⇒ Server
Returns a new instance of Server.
131 132 133 134 135 136 |
# File 'lib/imaginator.rb', line 131 def initialize(renderer) @renderer = renderer @queue = [] @queue.extend(MonitorMixin) @empty = @queue.new_cond end |
Instance Method Details
#enqueue(name, type, code) ⇒ Object
138 139 140 141 142 143 |
# File 'lib/imaginator.rb', line 138 def enqueue(name, type, code) @queue.synchronize do @queue << [name, type, code] @empty.signal end end |
#enqueued?(name) ⇒ Boolean
145 146 147 148 149 150 151 |
# File 'lib/imaginator.rb', line 145 def enqueued?(name) @queue.synchronize do @queue.any? do |x| x[0] == name end end end |
#run ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/imaginator.rb', line 153 def run loop do name, type, code = @queue.synchronize do return if !wait_while_empty @queue.first end @renderer[type].render(code, name) rescue nil @queue.synchronize do @queue.shift end end end |