em-synchrony using http.get and iterators causing can't yield in root Fiber error

867 views Asked by At

A very simple case where I get the root Fiber error.

require 'em-synchrony'
require 'em-synchrony/em-http'

urls = %w{http://www.google.com http://www.google.com http://www.google.com http://www.google.com http://www.google.com http://www.google.com}
EM.synchrony do

  EM::Synchrony::Iterator.new(urls, 2).each(
      proc { |url, iter|

        EM::HttpRequest.new(url).get
        iter.next
      }
  )
end

I can use async here, but not a sync http request.

1

There are 1 answers

1
keaplogik On BEST ANSWER

Looks like if I'm going to use the sync get request I should be using FiberIterator.

require 'em-synchrony'
require 'em-synchrony/em-http'
require "em-synchrony/fiber_iterator"

urls = %w{http://www.google.com http://www.google.com http://www.google.com http://www.google.com http://www.google.com http://www.google.com}
EM.synchrony do


  EM::Synchrony::FiberIterator.new(urls, 2).each(
      proc { |url|

        EM::HttpRequest.new(url).get

      }
  )
end