mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
avoid infinite loop on thin when running a modular application, fixes #369
This commit is contained in:
parent
d6fb8cc067
commit
1d002390e3
2 changed files with 9 additions and 1 deletions
|
@ -247,10 +247,13 @@ module Sinatra
|
|||
def self.defer(*) yield end
|
||||
|
||||
def initialize(scheduler = self.class, keep_open = false, &back)
|
||||
@back, @scheduler, @callbacks, @keep_open = back.to_proc, scheduler, [], keep_open
|
||||
@back, @scheduler, @keep_open = back.to_proc, scheduler, keep_open
|
||||
@callbacks, @closed = [], false
|
||||
end
|
||||
|
||||
def close
|
||||
return if @closed
|
||||
@closed = true
|
||||
@scheduler.schedule { @callbacks.each { |c| c.call }}
|
||||
end
|
||||
|
||||
|
|
|
@ -107,4 +107,9 @@ class StreamingTest < Test::Unit::TestCase
|
|||
scheduler.defer!
|
||||
assert_raise(RuntimeError) { scheduler.schedule! }
|
||||
end
|
||||
|
||||
it 'does not trigger an infinite loop if you call close in a callback' do
|
||||
stream = Stream.new { |out| out.callback { out.close }}
|
||||
stream.each { |str| }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue