Skip to content

Commit

Permalink
Use defer_stop in sleep example for graceful shutdown.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Apr 3, 2024
1 parent 896baed commit 84a9e1d
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions examples/sleep/config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,17 @@ require 'async'
run do
body = Async::HTTP::Body::Writable.new

Async do
30.times do
body.write "(#{Time.now}) Hello World #{Process.pid}\n"
sleep 1
Async do |task|
task.defer_stop do
30.times do
body.write "(#{Time.now}) Hello World #{Process.pid}\n"
sleep 1
end
end
ensure
Console.info(self, "Closing body...")
body.close
end

[200, {}, body]
end

# Run the server:
# > falcon serve --count 1 --bind http://localhost:9292

# Measure the concurrency:
# > benchmark-http concurrency -t 1.2 -c 0.9 http://localhost:9292

0 comments on commit 84a9e1d

Please sign in to comment.