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

  • Home
  • SEARCH
  • 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 8493121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:55:11+00:00 2026-06-10T22:55:11+00:00

Assume I have an I/O-bounded operations. I do have a callbacks (or em-synchrony) How

  • 0

Assume I have an I/O-bounded operations. I do have a callbacks (or em-synchrony)

  1. How does EM switch to proccess next request keeping previous one waiting for callback?
  2. How does it keep Thread.current variables isolated?
  3. How can I emulate long running jobs?
  • 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-10T22:55:12+00:00Added an answer on June 10, 2026 at 10:55 pm

    1. How does EM switch to proccess next request keeping previous one waiting for callback?

    In any reactor pattern there is a single thread of the execution. Meaning, only one thing can execute at a time. If the reactor is processing a request on that main thread, then no other request can intervene (cooperative scheduling). Now, the request can “relinquish” control either voluntarily (in EM, we have EM.next_tick { # block }), or by scheduling an operation in the future: a timer (EM.add_timer { #block }), or by making another IO operation!

    For example, if you’re using EM-Synchrony, then when you make an HTTP request (via em-http), then when the request is dispatched, the fiber is paused, and a callback is created for you under the hood.. When the request is finished, the callback is invoked by EventMachine, via an internal callback.. and control returns back to your request. For a more in-depth look:
    http://www.igvita.com/2010/03/22/untangling-evented-code-with-ruby-fibers/

    2. How does it keep Thread.current variables isolated?

    No magic. In Ruby, we have thread local variables: Thread.current[:foo] = bar. Similarly, Fiber’s have the same semantics, although what sometimes catches people off-guard is that the same mechanism is used.. aka Thread.current[:foo] = bar.

    See here: http://devblog.avdi.org/2012/02/02/ruby-thread-locals-are-also-fiber-local/

    3. How can I emulate long running jobs?

    Best approach: move them outside of the reactor. This is true of any reactor system.

    a) Create a job queue and push it to another process
    b) EM does provide EM.defer, which spawns another thread.

    Choose (a) whenever possible over (b).. you’ll thank yourself later.

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

Sidebar

Related Questions

Assume you have a function read_key and normally it does some stuff. You someone
Assume I have one threadpool and each thread is running following method: void runMe(HashMap
Assume I have 2 machines, one machine with MS windows with .NET 4.0 and
Assume I have templated dropdown list in my gridview (which is bounded to all
Assume you have five products, and all of them use one or more of
Assume I have one matrix with two columns. Every column has thousands of values.
Assume I have SomeExtension MarkupExtension. Does anyone know how to assign it to a
Assume I have two tables, Student Test Id Name TestId Type StudentId -- ----
Assume I have an enumerable object enum and now I want to get the
Assume I have the following ; def test(): while 1: a = b time.sleep(60)

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.