Non blocking merb actions
One of the most powerful features in merb is an action’s ability to return a proc, thus releasing the controller block and transferring control to the application server which will be able to handle requests in a parallel manner.
Consider the following controller.
class MyController < Application
def hello
render "hello"
end
def wait_and_hello
sleep 10
render "hello"
end
def dont_wait_to_hello
proc { sleep 10; p "hello" }
end
end
Start merb and access http://localhost:4000/my_controller/hello after visiting http://localhost:4000/my_controller/wait_and_hello. Ten seconds will pass before /my_controller/hello is served. A request to /my_controller/hello will be served immediately regardless of whether a preceding request to /my_controller/dont_wait_to_hello has completed.

April 17th, 2008 at 11:11 am
Apparently I need to dig into Merb, because this is an excellent feature. I wish I had known about this previously. Can that proc take an arbitrarily long time?
April 17th, 2008 at 12:55 pm
I assume it will depend on when the app server will time out the request.
April 17th, 2008 at 11:23 pm
[...] « Non blocking merb actions [...]