Project

thin_async

0.01
No commit activity in last 3 years
No release in over 3 years
A nice wrapper to send response body asynchronously with Thin
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 1.2.1
 Project Readme

Thin Asynchronous Response API

A nice wrapper around Thin's obscure async callback used to send response body asynchronously. Which means you can send the response in chunks while allowing Thin to process other requests.

Crazy delicious with em-http-request for file upload, image processing, proxying, etc.

WARNING

You should not use long blocking operations (Net::HTTP or slow shell calls) with this as it will prevent the EventMachine event loop from running and block all other requests.

Usage

Inside your Rack app #call(env):

Thin::AsyncResponse.perform(env) do |response|
  response.status = 201
  response.headers["X-Muffin-Mode"] = "ACTIVATED!"

  response << "this is ... "

  EM.add_timer(1) do
    # This will be sent to the client 1 sec later without blocking other requests.
    response << "async!"
    response.done
  end
end

See example/ dir for more.

(c) macournoyer