Skip to content

Commit

Permalink
add closed? method on Stream object to inspect the object's open/clos…
Browse files Browse the repository at this point in the history
…e state

Signed-off-by: Anurag Priyam <anurag08priyam@gmail.com>
  • Loading branch information
yeban committed Jun 24, 2012
1 parent 8adecc0 commit cc8502f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/sinatra/base.rb
Expand Up @@ -332,6 +332,10 @@ def callback(&block)
end

alias errback callback

def closed?
@closed
end
end

# Allows to start sending data to the client even though later parts of
Expand Down
7 changes: 7 additions & 0 deletions test/streaming_test.rb
Expand Up @@ -139,4 +139,11 @@ def close.errback; end
get '/'
assert ran
end

it 'has a public interface to inspect its open/closed state' do
stream = Stream.new(Stream) { |out| out << :foo }
assert !stream.closed?
stream.close
assert stream.closed?
end
end

0 comments on commit cc8502f

Please sign in to comment.