Created — forked from rkh/gist:418380

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View gist:1986273
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
class SomeMiddleware
def initialize(app) @app = app end
 
def call(env)
background(env) { ... }
@app.call env
end
 
def background(env, &block)
if env['rack.run_once'] then yield
elsif defined? EventMachine then EventMachine.next_tick(&block)
elsif env['rack.multithread'] or not supports_fork? then Thread.new(&block)
else fork(&block)
end
end
 
def supports_fork?
return @@supports_fork unless @@supports_fork.nil?
@@supports_fork = begin
fork { }
true
rescue NotImplementedError
false
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.