Class: RCelery::AsyncResult

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

Instance Method Summary collapse

Constructor Details

#initialize(task_id) ⇒ AsyncResult

Returns a new instance of AsyncResult.



3
4
5
6
# File 'lib/rcelery/async_result.rb', line 3

def initialize(task_id)
  @task_id = task_id
  @queue = Task.result_queue(task_id)
end

Instance Method Details

#waitObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rcelery/async_result.rb', line 8

def wait
  result_value = :no_result
  @queue.subscribe do |payload|
    result_value = JSON.parse(payload)['result']
  end

  while(result_value == :no_result)
    sleep(0.05)
  end

  @queue.unsubscribe
  result_value
end