From 84a9e1d296a6f6c17f12444c7920641ecc37a6e0 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Thu, 4 Apr 2024 11:04:23 +1300 Subject: [PATCH] Use `defer_stop` in sleep example for graceful shutdown. --- examples/sleep/config.ru | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/examples/sleep/config.ru b/examples/sleep/config.ru index e3ec94c2..5cbf373c 100644 --- a/examples/sleep/config.ru +++ b/examples/sleep/config.ru @@ -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 -