Skip to content

Commit 84a9e1d

Browse files
committed
Use defer_stop in sleep example for graceful shutdown.
1 parent 896baed commit 84a9e1d

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

examples/sleep/config.ru

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,17 @@ require 'async'
44
run do
55
body = Async::HTTP::Body::Writable.new
66

7-
Async do
8-
30.times do
9-
body.write "(#{Time.now}) Hello World #{Process.pid}\n"
10-
sleep 1
7+
Async do |task|
8+
task.defer_stop do
9+
30.times do
10+
body.write "(#{Time.now}) Hello World #{Process.pid}\n"
11+
sleep 1
12+
end
1113
end
1214
ensure
15+
Console.info(self, "Closing body...")
1316
body.close
1417
end
1518

1619
[200, {}, body]
1720
end
18-
19-
# Run the server:
20-
# > falcon serve --count 1 --bind http://localhost:9292
21-
22-
# Measure the concurrency:
23-
# > benchmark-http concurrency -t 1.2 -c 0.9 http://localhost:9292
24-

0 commit comments

Comments
 (0)