シンプルに処理を非同期にする

この程度で事足りる処理も多いと思う。
AsyncCallbackはenvironment.rbとかてきとーなトコで生成。

controller

class BarController < ApplicationController
  def index
    ASYNC_CALLBACK.invoke('あれあれ', 'しょりが', 'おくれて', 'はしるよ?') {|*args|
      args.each do |arg|
        puts "#{arg}".tosjis
        sleep 2
      end
    }

    render :text => 'hello'
  end
end

AsyncCallbackクラス

class AsyncCallback
  def initialize
    @queue = Queue.new
    
    Thread.fork {
      while func_args = @queue.pop
        func, args = func_args
        Thread.fork { func.call(*args) }
      end
    }
  end

  def invoke(*args, &block)
    @queue.push([block, args])
  end
end

ASYNC_CALLBACK = AsyncCallback.new