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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:00:33+00:00 2026-06-15T13:00:33+00:00

I need to process jobs off of a queue within a process, with IO

  • 0

I need to process jobs off of a queue within a process, with IO performed asynchronously. That’s pretty straightforward. The gotcha is that those jobs can add additional items to the queue.

I think I’ve been fiddling with this problem too long so my brain is cloudy — it shouldn’t be too difficult. I keep coming up with an either-or scenario:

  1. The queue can perform jobs asynchronously and results can be joined in afterward.
  2. The queue can synchronously perform jobs until the last finishes and the queue is empty.

I’ve been fiddling with everything from EventMachine and Goliath (both of which can use EM::HttpRequest) to Celluloid (never actually got around to building something with it though), and writing Enumerators using Fibers. My brain is fried though.

What I’d like, simply, is to be able to do this:

items = [1,2,3]
items.each do |item|
  if item.has_particular_condition? 
    items << item.process_one_way
  elsif item.other_condition?
    items << item.process_another_way
  # ...
  end
end

#=> [1,2,3,4,5,6]

…where 4, 5, and 6 were all results of processing the original items in the set, and 7, 8, and 9 are results from processing 4, 5, and 6. I don’t need to worry about indefinitely processing the queue because the data I’m processing will end after a couple of iterations.

High-level guidance, comments, links to other libraries, etc are all welcome, as well as lower-level implementation code examples.

  • 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-15T13:00:35+00:00Added an answer on June 15, 2026 at 1:00 pm

    I wound up implementing something a little less ideal — basically just wrapping an EM Fiber Iterator in a loop that terminates once no new results are queued.

    require 'set'
    
    class SetRunner
      def initialize(seed_queue)
        @results = seed_queue.to_set
      end
    
      def run
        begin
          yield last_loop_results, result_bucket
        end until new_loop_results.empty?
    
        return @results
      end
    
      def last_loop_results
        result_bucket.shift(result_bucket.count)
      end
    
      def result_bucket
        @result_bucket ||= @results.to_a
      end
    
      def new_loop_results
        # .add? returns nil if already in the set
        result_bucket.each { |item| @results.add? item }.compact
      end
    end
    

    Then, to use it with EventMachine:

    queue = [1,2,3]
    results = SetRunner.new(queue).run do |set, output|
      EM::Synchrony::FiberIterator.new(set, 3).each do |item|
        output.push(item + 3) if item <= 6
      end
    end
    # => [1,2,3,4,5,6,7,8,9]
    

    Then each set will get run with the concurrency level passed to the FiberIterator, but the results from each set will get run in the next iteration of the outer SetRunner loop.

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

Sidebar

Related Questions

I need to process a large C++ codebase, renaming pretty much everything (classes, parameters,
I am writing a multithreaded service that picks up jobs to process that has
I'm writing a background service that needs to process a series of jobs, stored
I need a FIFO queue implementation on PHP. I know that it's not so
I need to process URLs with JS and find out if they belong to
I need to process a large number of files in a directory. The files
I need to process a HTML content and replace the IMG SRC value with
I need to process the incoming predefined ASN format data(coming from verity of clients
I need to process DICOM formatted medical images and visualize them in 3D, also
I need to process messages in batches, lets say of 10. After 10 transactions

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.