Parallel :: Promise.all? does not work

I am trying to do some calculations after doing all the promises. But it procnever calls:

cbr_promise = Concurrent::Promise.execute { CbrRatesService.call }
bitfinex_promise = Concurrent::Promise.execute { BitfinexService.call }

proc = Proc.new do
  puts 10
end
Concurrent::Promise.all?([cbr_promise, bitfinex_promise]).then { proc }

Made with concurrent-rubygem.

Should I create a loop that will check this every 100 ms, for example?

Update

I tried to add a loop and execute the code (in sidekiqworker):

while @fl
  Concurrent::Promise.all?([cbr_promise, bitfinex_promise]).then { proc }
end

but statefor all promises makes up pending. It may be due to beebug, but procnever calls anyway .

+6
source share
1 answer
  • Concurrent::Promise.all?returns a Promiseand you must execute it
  • you need to pass procas a block argument&proc
  • Promises (, )

:

require 'concurrent'

cbr_promise       = Concurrent::Promise.new { p "cbr" }
bitfinex_promise  = Concurrent::Promise.new { p "bitfinex" }

proc = Proc.new do
  puts 10
end

e = Concurrent::Promise.all?(cbr_promise, bitfinex_promise).execute.then(&proc)

sleep 1

"cbr"
"bitfinex"
10

, proc, Promises :

require 'concurrent'

cbr_promise       = Concurrent::Promise.new { p "cbr" }
bitfinex_promise  = Concurrent::Promise.new { p "bitfinex"; raise 'error' }

proc = Proc.new do
  puts 10
end

e = Concurrent::Promise.all?(cbr_promise, bitfinex_promise).execute.then(&proc)

sleep 1

"cbr"
"bitfinex"
+4

All Articles