Class: Concur::EventMachineFuture
- Inherits:
-
Object
- Object
- Concur::EventMachineFuture
- Includes:
- Future
- Defined in:
- lib/futures/event_machine_future.rb
Instance Attribute Summary collapse
-
#ex ⇒ Object
Returns the value of attribute ex.
-
#result ⇒ Object
Returns the value of attribute result.
Instance Method Summary collapse
- #call ⇒ Object
- #complete ⇒ Object
- #complete? ⇒ Boolean
-
#get ⇒ Object
Returns results.
- #get_response ⇒ Object
-
#initialize(callable, &block) ⇒ EventMachineFuture
constructor
A new instance of EventMachineFuture.
- #run ⇒ Object
Methods included from Future
Constructor Details
#initialize(callable, &block) ⇒ EventMachineFuture
Returns a new instance of EventMachineFuture.
219 220 221 222 223 224 225 226 227 |
# File 'lib/futures/event_machine_future.rb', line 219 def initialize(callable, &block) @mutex = Mutex.new @cv = ConditionVariable.new @callable = callable if block_given? @callable = block end end |
Instance Attribute Details
#ex ⇒ Object
Returns the value of attribute ex.
217 218 219 |
# File 'lib/futures/event_machine_future.rb', line 217 def ex @ex end |
#result ⇒ Object
Returns the value of attribute result.
217 218 219 |
# File 'lib/futures/event_machine_future.rb', line 217 def result @result end |
Instance Method Details
#call ⇒ Object
258 259 260 |
# File 'lib/futures/event_machine_future.rb', line 258 def call run end |
#complete ⇒ Object
262 263 264 |
# File 'lib/futures/event_machine_future.rb', line 262 def complete @complete = true end |
#complete? ⇒ Boolean
267 268 269 |
# File 'lib/futures/event_machine_future.rb', line 267 def complete? @complete end |
#get ⇒ Object
Returns results. Will wait for thread to complete execution if not already complete.
272 273 274 275 276 277 278 279 280 |
# File 'lib/futures/event_machine_future.rb', line 272 def get # @thread.value while !@complete # todo: gotta be a better way puts 'sleeping' sleep 0.5 end return get_response end |
#get_response ⇒ Object
282 283 284 285 286 287 |
# File 'lib/futures/event_machine_future.rb', line 282 def get_response if @ex raise @ex end @result end |
#run ⇒ Object
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/futures/event_machine_future.rb', line 229 def run puts 'EMFuture.run' p @callable begin @callbackable = @callable.call(self) puts 'done @callable.call ' + @callbackable.inspect rescue Exception => ex @ex = ex end if @ex complete return end http = @callbackable http.errback2 { puts 'completion errback' @ex = EventMachineError.new(http) complete } @result = (http.callback2 { |result| puts 'completion errback' @result = result complete }) puts '@result=' + @result.inspect end |