Class: Concur::EventMachineFuture

Inherits:
Object
  • Object
show all
Includes:
Future
Defined in:
lib/futures/event_machine_future.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Future

#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

#exObject

Returns the value of attribute ex.



217
218
219
# File 'lib/futures/event_machine_future.rb', line 217

def ex
  @ex
end

#resultObject

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

#callObject



258
259
260
# File 'lib/futures/event_machine_future.rb', line 258

def call
  run
end

#completeObject



262
263
264
# File 'lib/futures/event_machine_future.rb', line 262

def complete
  @complete = true
end

#complete?Boolean

Returns:

  • (Boolean)


267
268
269
# File 'lib/futures/event_machine_future.rb', line 267

def complete?
  @complete
end

#getObject

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_responseObject



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

#runObject



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