diff --git a/README.md b/README.md index 0ef30a4b..2db8ba5e 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ The code you changed will not take effect until you restart the server. Please restart the server every time you change or use [sinatra/reloader](http://www.sinatrarb.com/contrib/reloader). -It is recommended to also run `gem install thin`, which Sinatra will +It is recommended to also run `gem install puma`, which Sinatra will pick up if available. ## Table of Contents @@ -1685,36 +1685,53 @@ to `stream` finishes executing. Streaming does not work at all with Shotgun. If the optional parameter is set to `keep_open`, it will not call `close` on the stream object, allowing you to close it at any later point in the -execution flow. This only works on evented servers, like Thin and Rainbows. +execution flow. This only works on evented servers, like Rainbows. Other servers will still close the stream: ```ruby -# long polling +# config.ru +require 'sinatra/base' -set :server, :thin -connections = [] +class App < Sinatra::Base + connections = [] -get '/subscribe' do - # register a client's interest in server events - stream(:keep_open) do |out| - connections << out - # purge dead connections - connections.reject!(&:closed?) + get '/subscribe' do + # register a client's interest in server events + stream(:keep_open) do |out| + connections << out + # purge dead connections + connections.reject!(&:closed?) + end + end + + post '/:message' do + connections.each do |out| + # notify client that a new message has arrived + out << params['message'] << "\n" + + # indicate client to connect again + out.close + end + + # acknowledge + "message received" end end -post '/:message' do - connections.each do |out| - # notify client that a new message has arrived - out << params['message'] << "\n" +run App +``` - # indicate client to connect again - out.close - end - - # acknowledge - "message received" +```ruby +# rainbows.conf +Rainbows! do + use :EventMachine end +```` + +Run: + +```shell +rainbows -c rainbows.conf ``` It's also possible for the client to close the connection when trying to @@ -2377,7 +2394,7 @@ set :protection, :session => true If you are using a WEBrick web server, presumably for your development environment, you can pass a hash of options to server_settings, such as SSLEnable or SSLVerifyClient. However, web - servers such as Puma and Thin do not support this, so you can set + servers such as Puma do not support this, so you can set server_settings by defining it as a method when you call configure. @@ -2428,7 +2445,7 @@ set :protection, :session => true