Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A nice wrapper to send response body asynchronously with Thin

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 example
Octocat-spinner-32 lib
Octocat-spinner-32 .gitignore
Octocat-spinner-32 README.md
Octocat-spinner-32 thin_async.gemspec
README.md

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):

response = Thin::AsyncResponse.new(env)
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

response.finish

See example/ dir for more.

(c) macournoyer

Something went wrong with that request. Please try again.