PasteRack.org
Paste # 85563
2018-12-06 13:06:12

Fork as a new paste.

Paste viewed 145 times.


Embed:

Graceful web server restarts

#lang racket/base

(require
 web-server/http/response
 web-server/http/response-structs
 web-server/web-server)

(define (hello-world conn req)
  (define r
    (response/output
     (λ (out)
       (write-bytes #"begin\n" out)
       (flush-output out)
       (sleep 10)
       (write-bytes #"end\n" out))))
  (output-response conn r))

(define stop (serve #:dispatch hello-world #:port 8000))
(with-handlers ([exn:break? (λ (e)
                              (printf "stopping...~n")
                              (stop))])
  (sync/enable-break never-evt))