Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8106051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:20:40+00:00 2026-06-06T00:20:40+00:00

I am trying to write parser (parse postal code’s streets and houses) with eventmachine

  • 0

I am trying to write parser (parse postal code’s streets and houses) with eventmachine and em-synchrony. The thing is that the website I want to parse has nested structure – for each postal code there are many pages of streets, which has pagination. So the algorithm is pretty simple:

  • for each postal code
    • visit postcal code index page
      • parse index page
      • parse pagination
      • for each pagination page parse this page

Here is an example of such a parser (it works):

require "nokogiri"
require "em-synchrony"
require "em-synchrony/em-http"

def url page = nil
  url = "http://gistflow.com/all"
  url << "?page=#{page}" if page
  url
end

EM.synchrony do
  concurrency = 2

  # here [1] is array of index pages, for this template let it be just [1]
  results = EM::Synchrony::Iterator.new([1], concurrency).map do |index, iter|
    index_page = EM::HttpRequest.new(url).aget

    index_page.callback do
      # here we make some parsing and find out wheter index page 
      # has pagination. The worst case is that it has pagination
      pages = [2,3,4,5]

      unless pages.empty?
        # here we need to parse all pages
        # with urls like url(page)
        # how can I do it more efficiently?
      end

      iter.return "SUCC #{index}"
    end

    index_page.errback do 
      iter.return "ERR #{index}"
    end
  end

  p results
  EM.stop
end

So the trick is inside this block:

unless pages.empty?
  # here we need to parse all pages
  # with urls like url(page)
  # how can I do it more efficiently?
end

How can I implement nested EM HTTP calls inside synchrony iterator loop?

I was trying different approaches but each time I got errors like “couldn’t yield from root fiber” or errback block was called.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T00:20:42+00:00Added an answer on June 6, 2026 at 12:20 am

    One solution is to use FiberIterator and the synchronous .get instead of .aget:

    require "em-synchrony"
    require "em-synchrony/em-http"
    require "em-synchrony/fiber_iterator"
    
    def url page = nil
      url = "http://gistflow.com/all"
      url << "?page=#{page}" if page
      url
    end
    
    EM.synchrony do
      concurrency = 2
    
      master_pages = [1,2,3,4]
    
      EM::Synchrony::FiberIterator.new(master_pages, concurrency).each do |iter|
        result = EM::HttpRequest.new(url).get
        if result
          puts "SUCC #{iter}"
          detail_pages = [1,2,3,4]       
          EM::Synchrony::FiberIterator.new(detail_pages, concurrency).each do |iter2|
            result2 = EM::HttpRequest.new(url).get
            puts "SUCC/ERR #{iter} > #{iter2}"
          end
        else
          puts "ERR #{iter}"
        end
      end
    
      EM.stop
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a piece of code that can parse any xml
I'm trying to write a parser using Parsec that will parse literate Haskell files,
I'm trying to write a Perl script that will parse the output of the
Trying to write a code at the moment that basically tests to see if
I'm trying to write an XML parser that takes an RSS feed & fetches
I am trying to write a simple RSS parser for my website. Although I
I am trying to write a script that will parse a directory, find the
I'm trying to write a SAX parser for an XHTML document that I download
I'm trying to write a parser that uses two characters as token boundaries, but
I am trying to write an ANTLR parser rule that matches a list of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.