diff --git a/minimart/examples/chat-userland.rkt b/minimart/examples/chat-userland.rkt index f3815eb..7e85d08 100644 --- a/minimart/examples/chat-userland.rkt +++ b/minimart/examples/chat-userland.rkt @@ -15,15 +15,15 @@ (define (say who fmt . vs) (unless (equal? who user) (send-to-remote "~a ~a\n" who (apply format fmt vs)))) - (define remote-detector (pub #:meta-level 1 #:level 1 (tcp-channel us them ?))) + (define tcp-gestalt (gestalt-union (pub (tcp-channel us them ?) #:meta-level 1 #:level 1) + (pub (tcp-channel us them ?) #:meta-level 1) + (sub (tcp-channel them us ?) #:meta-level 1))) - (userland-thread #:gestalt (gestalt-union (sub `(,? says ,?)) + (userland-thread #:gestalt (gestalt-union tcp-gestalt + (sub `(,? says ,?)) (sub `(,? says ,?) #:level 1) - (pub `(,user says ,?)) - (sub (tcp-channel them us ?) #:meta-level 1) - (pub (tcp-channel us them ?) #:meta-level 1) - remote-detector) - (wait-for-gestalt remote-detector) + (pub `(,user says ,?))) + (wait-for-gestalt tcp-gestalt) (send-to-remote "Welcome, ~a.\n" user) (let loop ((old-peers (set))) (match (next-event) @@ -34,10 +34,9 @@ (say who "says: ~a" what) (loop old-peers)] [(routing-update g) - (define remote-present? (not (gestalt-empty? (gestalt-filter g remote-detector)))) + (when (gestalt-empty? (gestalt-filter g tcp-gestalt)) (do (quit))) (define new-peers (matcher-key-set/single (gestalt-project g 0 0 #t (compile-gestalt-projection `(,(?!) says ,?))))) - (when (not remote-present?) (do (quit))) (for/list [(who (set-subtract new-peers old-peers))] (say who "arrived.")) (for/list [(who (set-subtract old-peers new-peers))] (say who "departed.")) (loop new-peers)])))) diff --git a/minimart/examples/chat-userland2.rkt b/minimart/examples/chat-userland2.rkt index e7f085a..385a409 100644 --- a/minimart/examples/chat-userland2.rkt +++ b/minimart/examples/chat-userland2.rkt @@ -20,8 +20,9 @@ (userland-thread #:gestalt tcp-gestalt (wait-for-gestalt tcp-gestalt) - (send-to-remote "Welcome. What is your name? > ") + (send-to-remote "What is your name? > ") (define user (read-chunk)) + (send-to-remote "Welcome, ~a.\n" user) (do (routing-update (gestalt-union tcp-gestalt (sub `(,? says ,?) #:level 1) @@ -41,10 +42,9 @@ (say who "says: ~a" what) (loop old-peers)] [(routing-update g) - (define remote-present? (not (gestalt-empty? (gestalt-filter g tcp-gestalt)))) + (when (gestalt-empty? (gestalt-filter g tcp-gestalt)) (do (quit))) (define new-peers (matcher-key-set/single (gestalt-project g 0 0 #t (compile-gestalt-projection `(,(?!) says ,?))))) - (when (not remote-present?) (do (quit))) (for/list [(who (set-subtract new-peers old-peers))] (say who "arrived.")) (for/list [(who (set-subtract old-peers new-peers))] (say who "departed.")) (loop new-peers)]))))