Permalink
Browse files

change the stream API while we still can

  • Loading branch information...
1 parent 9385dd8 commit b7b289053bde6c6193db4db26821d69edf565315 @rkh rkh committed Sep 1, 2011
Showing with 43 additions and 31 deletions.
  1. +6 −6 README.es.rdoc
  2. +30 −18 README.rdoc
  3. +5 −5 lib/sinatra/base.rb
  4. +2 −2 test/streaming_test.rb
View
12 README.es.rdoc
@@ -872,18 +872,18 @@ WEBRick, no soporten streaming directamente, así el cuerpo de la respuesta ser
enviado completamente de una vez cuando el bloque pasado a +stream+ finalice su
ejecución.
-Cuando se pasa +false+ como parámetro, no se va a enviar el mensaje +close+ al
-objeto de stream. Queda en vos cerrarlo en el punto de ejecución que quieras.
-Nuevamente, hay que tener en cuenta que este comportamiento es posible solo en
-servidores que soporten eventos, como Thin o Rainbows. El resto de los
-servidores van a cerrar el stream de todos modos.
+Cuando se pasa +keep_open+ como parámetro, no se va a enviar el mensaje
++close+ al objeto de stream. Queda en vos cerrarlo en el punto de ejecución
+que quieras. Nuevamente, hay que tener en cuenta que este comportamiento es
+posible solo en servidores que soporten eventos, como Thin o Rainbows. El
+resto de los servidores van a cerrar el stream de todos modos.
set :server, :thin
conexiones = []
get '/' do
# mantenemos abierto el stream
- stream(false) { |salida| conexiones << salida }
+ stream(:keep_open) { |salida| conexiones << salida }
end
post '/' do
View
48 README.rdoc
@@ -845,17 +845,17 @@ like WEBRick, might not even support streaming at all. If the server does not
support streaming, the body will be sent all at once after the block passed to
+stream+ finished executing.
-If the optional parameter is set to +false+, 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. Other
-servers will still close the stream.
+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.
+Other servers will still close the stream.
set :server, :thin
connections = []
get '/' do
# keep stream open
- stream(false) { |out| connections << out }
+ stream(:keep_open) { |out| connections << out }
end
post '/' do
@@ -1769,47 +1769,59 @@ The following Ruby versions are officially supported:
[ Ruby 1.8.7 ]
1.8.7 is fully supported, however, if nothing is keeping you from it, we
- recommend upgrading to 1.9.2 or switching to JRuby or Rubinius.
+ recommend upgrading to 1.9.2 or switching to JRuby or Rubinius. Support for
+ 1.8.7 will not be dropped before Sinatra 2.0 and Ruby 2.0 except maybe for
+ the unlikely event of 1.8.8 being released. Even then, we might continue
+ supporting it. <b>Ruby 1.8.6 is no longer supported.</b> If you want to run
+ with 1.8.6, downgrade to Sinatra 1.2, which will receive bug fixes until
+ Sinatra 1.4.0 is released.
[ Ruby 1.9.2 ]
- 1.9.2 is supported and recommended. Note that Radius and Markaby are
- currently not 1.9 compatible. Do not use 1.9.2p0, it is known to cause
- segmentation faults when running Sinatra.
+ 1.9.2 is fully supported and recommended. Note that Radius and Markaby
+ are currently not 1.9 compatible. Do not use 1.9.2p0, it is known to cause
+ segmentation faults when running Sinatra. Support will continue at least
+ until the release of Ruby 1.9.4/2.0 and support for the latest 1.9 release
+ will continue as long as it is still supported by the Ruby core team.
+
+[ Ruby 1.9.3 ]
+ While we test against 1.9.3 we do not know of anyone using it in
+ production yet, and as with 1.9.2, you might want to be careful with
+ patch level zero.
[ Rubinius ]
- Rubinius is officially supported (Rubinius >= 1.2.3), everything, including
+ Rubinius is officially supported (Rubinius >= 1.2.4), everything, including
all template languages, works.
[ JRuby ]
- JRuby is officially supported (JRuby >= 1.6.1). No issues with third party
+ JRuby is officially supported (JRuby >= 1.6.3). No issues with third party
template libraries are known, however, if you choose to use JRuby, please
look into JRuby rack handlers, as the Thin web server is not fully supported
on JRuby. JRuby's support for C extensions is still experimental, which only
affects RDiscount and Redcarpet at the moment.
-<b>Ruby 1.8.6 is no longer supported.</b> If you want to run with 1.8.6,
-downgrade to Sinatra 1.2, which will receive bug fixes until Sinatra 1.4.0 is
-released.
-
We also keep an eye on upcoming Ruby versions.
The following Ruby implementations are not officially supported but still are
known to run Sinatra:
* Older versions of JRuby and Rubinius
+* Ruby Enterprise Edition
* MacRuby, Maglev, IronRuby
-* Ruby 1.9.0 and 1.9.1
+* Ruby 1.9.0 and 1.9.1 (but we do recommend against using those)
Not being officially supported means if things only break there and not on a
supported platform, we assume it's not our issue but theirs.
-We also run our CI against ruby-head (the upcoming 1.9.3), but we can't
-guarantee anything, since it is constantly moving. Expect 1.9.3p0 to be
+We also run our CI against ruby-head (the upcoming 1.9.4), but we can't
+guarantee anything, since it is constantly moving. Expect 1.9.4p0 to be
supported.
Sinatra should work on any operating system supported by the chosen Ruby
implementation.
+You will not be able to run Sinatra on Cardinal, SmallRuby, BlueRuby or any
+Ruby version prior to 1.8.7 as of the time being.
+
== The Bleeding Edge
If you would like to use Sinatra's latest bleeding code, feel free to run your
View
10 lib/sinatra/base.rb
@@ -245,8 +245,8 @@ class Stream
def self.schedule(*) yield end
def self.defer(*) yield end
- def initialize(scheduler = self.class, close = true, &back)
- @back, @scheduler, @callback, @close = back.to_proc, scheduler, nil, close
+ def initialize(scheduler = self.class, keep_open = false, &back)
+ @back, @scheduler, @callback, @keep_open = back.to_proc, scheduler, nil, keep_open
end
def close
@@ -261,7 +261,7 @@ def each(&front)
rescue Exception => e
@scheduler.schedule { raise e }
end
- close if @close
+ close unless @keep_open
end
end
@@ -283,9 +283,9 @@ def callback(&block)
# The close parameter specifies whether Stream#close should be called
# after the block has been executed. This is only relevant for evented
# servers like Thin or Rainbows.
- def stream(close = true, &block)
+ def stream(keep_open = false, &block)
scheduler = env['async.callback'] ? EventMachine : Stream
- body Stream.new(scheduler, close, &block)
+ body Stream.new(scheduler, keep_open, &block)
end
# Specify response freshness policy for HTTP caches (Cache-Control header).
View
4 test/streaming_test.rb
@@ -47,10 +47,10 @@ class StreamingTest < Test::Unit::TestCase
assert_equal 10, final
end
- it 'does not trigger the callback if close is set to false' do
+ it 'does not trigger the callback if close is set to :keep_open' do
step = 0
final = 0
- stream = Stream.new(Stream, false) { |o| 10.times { step += 1 } }
+ stream = Stream.new(Stream, :keep_open) { |o| 10.times { step += 1 } }
stream.callback { final = step }
stream.each { |str| }
assert_equal 0, final

0 comments on commit b7b2890

Please sign in to comment.