Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I am working on a smallish web framework for serving web services, totally asynchronously.A Sample controller looks like this:
- class HomeController < MsfService::Controller
- def index
- request_lamda = lambda do |t|
- t.quote("IBM")
- end
- response_lambda = lambda do |quote|
- @ready_to_render = true
- render :html => "#{quote.last}"
- end
- backend_server.defer(request_lamda,response_lambda)
- end
- end
- In a word when data request in request proc is ready then only view is rendered. So, I can't invoke call then and there as rack specification requires and hence I have modified thin a bit so as:
- def process
- @request.threaded = false
- pre_process
- end
- def pre_process
- # Add client info to the request env
- @request.remote_address = remote_address
- # Process the request calling the Rack adapter
- @app.call(@request.env) do |result|
- post_process(result)
- end
- rescue Object
- handle_error
- terminate_request
- post_process(nil) # Signal to post_process that the request could not be processed
- end
- Originally post_process immediately gets called after pre_process, but here I am attaching post_process as a lambda so as it gets called only when response is ready. Above code works, but it partially breaks rack. I am unable to use CommonLogger or other helper classes.
Add Comment
Please, Sign In to add comment