From 89690c6de9820e7a4f4fe1418067470a93c31973 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Mon, 29 Sep 2014 21:10:59 -0600 Subject: [PATCH] 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. --- .../htdp-lib/2htdp/private/world.rkt | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pkgs/htdp-pkgs/htdp-lib/2htdp/private/world.rkt b/pkgs/htdp-pkgs/htdp-lib/2htdp/private/world.rkt index cd71105598..333029fb6e 100644 --- a/pkgs/htdp-pkgs/htdp-lib/2htdp/private/world.rkt +++ b/pkgs/htdp-pkgs/htdp-lib/2htdp/private/world.rkt @@ -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*])