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

The Archive Base Latest Questions

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

I have a weird problem with aRuby program I’m writing. Basically the idea is

  • 0

I have a weird problem with aRuby program I’m writing.

Basically the idea is for the program to run constantly in the background. The program checks my browser history every 30 seconds and uploads any new history items to a server.

# client.rb
history = HistoryUploader.new(Chrome)
# Run everything
loop do
  history.run
  sleep 30
end

The important part of the HistoryUploader class looks like this

class HistoryUploader
  def run
    upload_history until local.last_seen_history_item == server.last_seen_history_item
  end

  def upload_history
    # POST batches of history items to the server
  end
end

The main problem I see with this code is that if HistoryUploader.run takes more than 30 seconds to complete (which it very well may since it is sending multiple http requests), the outside loop in client.rb will attempt to call run again and I could get parallel requests going to the server which would really confuse things.

Is there a way that I can block the run method from being called twice until it has finished?

  • 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:34:33+00:00Added an answer on May 28, 2026 at 3:34 pm

    I would use a request queue which executes requests one after another. You can also put a simple boolean flag inside HistoryUploader e.g. @is_uploading:

    class HistoryUploader
    
      attr_accessor :is_uploading
    
      def initialize
        @is_uploading = false
      end
    
      def run
        if @is_uploading
            return
        end     
        upload_history until local.last_seen_history_item == server.last_seen_history_item
      end
    
      def upload_history
        @is_uploading = true
        # POST batches of history items to the server
        # On uploading finished: 
        @is_uploading = false
      end
    end
    

    If you really want to block the main loop until the uploading is finished you can dispatch a thread and wait for it to finish using join:

    require 'thread'
    
    t = Thread.new do
        #post to server
    end
    t.join
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a weird problem. When I run this script I get 10 records
I have weird problem. I'm using Eclipse for writing J2EE (java, jsf, javascript) application
i have a weird problem. Basically, in my settings.py file i have 4 variables
I have weird problem with this code: if I run it like shown below
i have a weird problem. i would like to delete an assembly(plugin.dll on harddisk)
I have a weird problem with images in visual web developer, I cant change
I have a weird problem where after setting nocheck on a foreign constraint and
I have this weird problem with setting up cookies with PHP. Everything worked fine
I have a weird problem that i can't figure out a solution for: I've
I have a weird problem, and I don't know if this is the default

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.