Entersenate chat-sync.rkt

This commit is contained in:
Tony Garnock-Jones 2012-07-17 11:53:14 -04:00
parent 8f897119a9
commit 732010a40a
1 changed files with 6 additions and 10 deletions

View File

@ -22,18 +22,14 @@
(let loop ()
(sync (wrap-evt (read-bytes-line-evt cin 'any)
(lambda (line)
(if (eof-object? line)
'done
(begin
(call-with-semaphore active-connection-mutex
(lambda ()
(for ([c active-connections])
(thread-send (car c) `(says ,connection-id ,line)))))
(loop)))))
(cond [(eof-object? line) 'done]
[else
(for ([c active-connections])
(thread-send (car c) `(says ,connection-id ,line)))
(loop)])))
(wrap-evt (thread-receive-evt)
(lambda (dummy)
(define message (thread-receive))
(write message cout)
(write (thread-receive) cout)
(newline cout)
(flush-output cout)
(loop)))))