Skip to content

Commit

Permalink
fixup! Extract spec/std/http/spec_helper
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Dec 19, 2018
1 parent 85e7787 commit 89b00ee
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions spec/std/http/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ end
# 4. Ensures the server is closed.
# 5. After returning from the block, it waits for the server to gracefully
# shut down before continuing execution in the current fiber.
# 6. If the listening fiber raises an exception, it is rescued and re-reraised
# in the current fiber.
def run_server(server)
server_done = Channel(Nil).new
server_done = Channel(Exception).new

spawn do
server.listen
ensure
rescue exc
server_done.send exc
else
server_done.send nil
end

Expand All @@ -34,6 +38,9 @@ def run_server(server)
yield server_done
ensure
server.close unless server.closed?
server_done.receive

if exc = server_done.receive
raise exc
end
end
end

0 comments on commit 89b00ee

Please sign in to comment.