0
@some_instance_var = Concurrent::Hash.new   
(0...some.length).each do |idx|
  fetch_requests[idx] = Concurrent::Promise.execute do
    response = HTTP.get(EXTDATA_URL)

    if response.status.success?
      ... # update @some_instance_var
    end
    # We're going to disregard GET failures here.
    puts "I'm here"
  end
end
Concurrent::Promise.all?(fetch_requests).execute.wait    # let threads finish gathering all of the unique posts first
puts "how am i out already"

When I run this, the bottom line prints first, so it's not doing what I want of waiting for all the threads in the array to finish its work first, hence I keep getting an empty @some_instance_var to work with below this code. What am I writing wrong?

Bmr
  • 23
  • 4

1 Answers1

1

Never mind, I fixed this. That setup is correct, I just had to use the splat operator * for my fetch_requests array inside the all?().

Concurrent::Promise.all?(*fetch_requests).execute.wait

I guess it wanted multiple args instead of one array.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Bmr
  • 23
  • 4