template_streaming 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.0.9 2010-04-29
2
+
3
+ * Add support for Thin on Ruby 1.8.6.
4
+
1
5
  == 0.0.8 2010-04-28
2
6
 
3
7
  * Ensure Rack::Chunked is at the base of the middleware stack.
@@ -1,5 +1,5 @@
1
1
  module TemplateStreaming
2
- VERSION = [0, 0, 8]
2
+ VERSION = [0, 0, 9]
3
3
 
4
4
  class << VERSION
5
5
  include Comparable
@@ -26,7 +26,6 @@ module TemplateStreaming
26
26
  def render_with_template_streaming(*args, &block)
27
27
  with_template_streaming_condition(*args) do |condition|
28
28
  if condition
29
- check_thin_support
30
29
  @performed_render = true
31
30
  @streaming_body = StreamingBody.new(progressive_rendering_threshold) do
32
31
  @performed_render = false
@@ -137,24 +136,12 @@ module TemplateStreaming
137
136
  end
138
137
  end
139
138
 
140
- def check_thin_support
141
- return if defined?(@thin_support_found)
142
- if (@thin_callback = request.env['async.callback'])
143
- begin
144
- require 'event_machine_flush'
145
- @thin_support_found = true
146
- rescue LoadError
147
- raise "Template Streaming on Thin requires the event_machine_flush gem."
148
- end
149
- end
150
- end
151
-
152
139
  #
153
140
  # Force EventMachine to flush its buffer when using Thin.
154
141
  #
155
142
  def flush_thin
156
- @thin_callback and
157
- EventMachineFlush.flush(@thin_callback.receiver)
143
+ connection = request.env['template_streaming.thin_connection'] and
144
+ EventMachineFlush.flush(connection)
158
145
  end
159
146
  end
160
147
 
@@ -265,3 +252,34 @@ module TemplateStreaming
265
252
  ActionController::Response.send :include, Response
266
253
  ActionController::Dispatcher.middleware.insert 0, Rack::Chunked
267
254
  end
255
+
256
+ # Please let there be a better way to do this...
257
+ #
258
+ # We need to force Thin (EventMachine, really) to flush its output
259
+ # buffer before ending the current EventMachine tick. We can't use
260
+ # EventMachine.defer or .next_tick, as that would require returning
261
+ # from the call to the response body's #each. I'm not convinced Thin
262
+ # could even be rearchitected to support this without resorting to
263
+ # Threads, Continuations, or Fibers.
264
+ #
265
+ # Here, we hack Thin to add a handle to the connection object to the
266
+ # request environment, which we pass to EventMachineFlush, a horrid
267
+ # C++ hack. In ruby 1.8.7 we could use env[async.callback].receiver,
268
+ # but we want to support 1.8.6 for now too.
269
+ if defined?(Thin)
270
+ begin
271
+ require 'event_machine_flush'
272
+ rescue LoadError
273
+ raise "Template Streaming on Thin requires the event_machine_flush gem."
274
+ end
275
+
276
+ Rails.configuration.after_initialize do
277
+ Thin::Connection.class_eval do
278
+ def pre_process_with_template_streaming(*args, &block)
279
+ @request.env['template_streaming.thin_connection'] = self
280
+ pre_process_without_template_streaming(*args, &block)
281
+ end
282
+ alias_method_chain :pre_process, :template_streaming
283
+ end
284
+ end
285
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 8
9
- version: 0.0.8
8
+ - 9
9
+ version: 0.0.9
10
10
  platform: ruby
11
11
  authors:
12
12
  - George Ogata
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-28 00:00:00 -04:00
17
+ date: 2010-04-29 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency