2htdp/universe: adjust world loop to make it a loop

Similar to the server-side problem, but on the client side. In a
game where the server drives the clients with frequent messages
through `on-tick`, per-message growth in the continuation can
matter a lot.
This commit is contained in:
Matthew Flatt 2014-09-29 21:10:59 -06:00
parent 346365f64c
commit 89690c6de9

View File

@ -91,17 +91,17 @@
in
(lambda (in)
(define dis (text "the universe disappeared" 11 'red))
(with-handlers ((tcp-eof?
(compose (handler #f)
(lambda (e)
(set! draw (lambda (w) dis))
(pdraw)
e))))
;; --- "the universe disconnected" should come from here ---
(define msg (tcp-receive in))
(cond
[(sexp? msg) (prec msg) (RECEIVE)] ;; break loop if EOF
[#t (error 'RECEIVE "sexp expected, received: ~e" msg)]))))))
((with-handlers ((tcp-eof?
(compose (handler #f)
(lambda (e)
(set! draw (lambda (w) dis))
(pdraw)
(lambda () e)))))
;; --- "the universe disconnected" should come from here ---
(define msg (tcp-receive in))
(cond
[(sexp? msg) (prec msg) RECEIVE] ;; break loop if EOF
[#t (error 'RECEIVE "sexp expected, received: ~e" msg)])))))))
RECEIVE)
;; --- now register, obtain connection, and spawn a thread for receiving
(parameterize ([current-custodian *rec*])