Class: ActionController::Live::Buffer

Inherits:
ActionDispatch::Response::Buffer show all
Includes:
MonitorMixin
Defined in:
lib/action_controller/metal/live.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from ActionDispatch::Response::Buffer

#closed?

Constructor Details

#initialize(response) ⇒ Buffer

Returns a new instance of Buffer.



112
113
114
115
116
# File 'lib/action_controller/metal/live.rb', line 112

def initialize(response)
  @error_callback = lambda { true }
  @cv = new_cond
  super(response, SizedQueue.new(10))
end

Instance Method Details

#await_closeObject



143
144
145
146
147
# File 'lib/action_controller/metal/live.rb', line 143

def await_close
  synchronize do
    @cv.wait_until { @closed }
  end
end

#call_on_errorObject



153
154
155
# File 'lib/action_controller/metal/live.rb', line 153

def call_on_error
  @error_callback.call
end

#closeObject



135
136
137
138
139
140
141
# File 'lib/action_controller/metal/live.rb', line 135

def close
  synchronize do
    super
    @buf.push nil
    @cv.broadcast
  end
end

#eachObject



127
128
129
130
131
132
133
# File 'lib/action_controller/metal/live.rb', line 127

def each
  @response.sending!
  while str = @buf.pop
    yield str
  end
  @response.sent!
end

#on_error(&block) ⇒ Object



149
150
151
# File 'lib/action_controller/metal/live.rb', line 149

def on_error(&block)
  @error_callback = block
end

#write(string) ⇒ Object



118
119
120
121
122
123
124
125
# File 'lib/action_controller/metal/live.rb', line 118

def write(string)
  unless @response.committed?
    @response.headers["Cache-Control"] = "no-cache"
    @response.headers.delete "Content-Length"
  end

  super
end