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 7171555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:26:15+00:00 2026-05-28T15:26:15+00:00

The em-synchrony documentation links to this article which implies that this code with fiber:

  • 0

The em-synchrony documentation links to this article which implies that this code with fiber:

require 'eventmachine'
require 'fiber'
require 'em-http-request'

def http_get(url)
  f = Fiber.current
  http = EventMachine::HttpRequest.new(url).get

  # resume fiber once http call is done
  http.callback { f.resume(http) }
  http.errback  { f.resume(http) }

  return Fiber.yield
end

EventMachine.run do
  Fiber.new {
    page = http_get('http://myurl')
    puts "Fetched page: #{page.response}"
    EventMachine.stop
  }.resume

end

…is equivalent to this much simpler code using em-synchrony:

require 'em-synchrony'
require 'em-http-request'

EventMachine.synchrony do
  page = EventMachine::HttpRequest.new("http://myurl").get

  p "No callbacks! Fetched page: #{page.response}"
  EventMachine.stop
end

However running the two produces different results. In the first the fiber yields until the HTML response comes back, while the second seems to print immediately without waiting for the response and as a result the printed response is empty. Am I misreading or mistyping, or is the article actually suggesting the wrong thing?

  • 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-05-28T15:26:16+00:00Added an answer on May 28, 2026 at 3:26 pm

    You need to use extended version of EventMachine::HttpRequest that knows how to work with EventMachine.synchrony.

    Change

    require 'em-http-request'
    

    to

    require "em-synchrony/em-http" 
    

    This in turn will require “em-http-request” and will patch #get, #head, #post, #delete, #put methods of EventMachine::HttpRequest to work with Fibers.

    Here is the link to source code of em-synchrony/em-http.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This program require 'em-synchrony' ## v1.0.0 require 'em-hiredis' ## v0.1.0 module EventMachine module Hiredis
I'm working on an app that makes several Http Request to a RESTFULL web
Is this the correct way of handling Redis connection pooling with Sinatra Synchrony ?
em-synchrony.rb implements this feature with Fibers but I would go for a non-Fibre version
I'm doing a very silly benchmark on the ReaderWriterLock with this code, where reading
For manipulating a database I've created a class DBAdapter() that extends SQLiteHelper...this class has
This page in the MS documentation , covering asynchrony in Windows Forms applications, states:
I have written a game in PlayN, which has to communicate with a JavaEE-Server
I'm not sure that I really understand how Sinatra works. I'd like to get
I have a label with a format ever should be: 00:00:00. This timer should

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.