Skip to content

Commit

Permalink
Ensure the order of #close is consistent.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Oct 21, 2024
1 parent df4d6d1 commit 33d1faf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/protocol/http/body/completable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ def rewind
end

def close(error = nil)
super.tap do
if @callback
@callback.call(error)
@callback = nil
end
if @callback
@callback.call(error)
@callback = nil
end

super
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions test/protocol/http/body/completable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,18 @@
expect(completable.rewind).to be == false
end
end

with "#close" do
let(:events) {Array.new}
let(:callback) {Proc.new{events << :close}}

it "invokes callback once" do
completable1 = subject.new(body, proc{events << :close1})
completable2 = subject.new(completable1, proc{events << :close2})

completable2.close

expect(events).to be == [:close2, :close1]
end
end
end

0 comments on commit 33d1faf

Please sign in to comment.