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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:03:01+00:00 2026-06-16T22:03:01+00:00

I am fairly new to ruby mutli-threading and was confused on how to get

  • 0

I am fairly new to ruby mutli-threading and was confused on how to get started. I am currently building an app and it needs to fetch a LOT of images so I want to do it in a different thread. I wanted the program to execute as shown in the code below.

PROBLEM: The problem I see here is that the bar_method will get done fetching faster and the thread will end so things will keep getting added to the queue but won’t be processed. Is there any way of synchronization possible that will alert the bar_method thread that a new item has been added to the queue and if bar_method does finish earlier it should go to sleep and wait on a new item to be added to the queue?

def foo_method 
  queue created - consists of url to fetch and a callback method
  synch = Mutex.new
  Thread.new do
    bar_method synch, queue 
  end
  100000.times do
    synch.synchronize do
      queue << {url => img_url, method_callback => the_callback}
    end
  end
end
def bar_method synch_obj, queue
  synch_obj.synchronize do
    while queue isn't empty
        pop the queue. fetch image and call the callback
    end   
  end
end 
  • 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-16T22:03:02+00:00Added an answer on June 16, 2026 at 10:03 pm

    If you need to retrieve files from the internet, and use parallel requests, I’ll highly recommend Typhoeus and Hydra.

    From the documentation:

    hydra = Typhoeus::Hydra.new
    10.times.map{ hydra.queue(Typhoeus::Request.new("www.example.com", followlocation: true)) }
    hydra.run
    

    You can set the number of concurrent connections in Hydra:

    :max_concurrency (Integer) — Number of max concurrent connections to create. Default is 200.

    As a second recommendation look into Curb. Again, from its documentation:

    # make multiple GET requests
    easy_options = {:follow_location => true}
    multi_options = {:pipeline => true}
    
    Curl::Multi.get('url1','url2','url3','url4','url5', easy_options, multi_options) do|easy|
      # do something interesting with the easy response
      puts easy.last_effective_url
    end
    

    Both are built on top of Curl, so there’s no real difference in their underlying technology or its robustness. The difference is the commands available to you.

    Another gem that gets a lot of attention is EventMachine. It has EM-HTTP-Request which allows concurrent requests:

    EventMachine.run {
      http1 = EventMachine::HttpRequest.new('http://google.com/').get
      http2 = EventMachine::HttpRequest.new('http://yahoo.com/').get
    
      http1.callback { }
      http2.callback { } 
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

fairly new iPhone developer here. Building an app to send RS232 commands to a
I'm fairly new to Ruby on Rails and within my app the user is
I'm fairly new to ruby and I've got a hash that looks like so:
I am fairly new to ruby and I am trying to execute a spec
I'm fairly new to Ruby on Rails, and I'm attempting to create some fancy
Fairly new to programming. I just can't wrap my head around how to get
I'm fairly new to Ruby on Rails / Git and had a few questions
I'm fairly new in the Ruby + Rails scene. Although I have a very
I'm fairly new to ruby, and am configuring IRB. I like pretty print (require
I am fairly new to Ruby on Rails, and I clearly have an active

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.