Spice up the example a little

This commit is contained in:
Tony Garnock-Jones 2012-01-13 16:22:31 -05:00
parent 79741ab7b6
commit 28452b10f3
1 changed files with 13 additions and 3 deletions

View File

@ -1,5 +1,6 @@
#lang racket/base
(require racket/match)
(require racket/port)
(require "os-big-bang.rkt")
@ -40,8 +41,13 @@
(subscribe 'display-driver display-driver-handler)
(subscribe 'read-line-driver read-line-driver-handler)
(tick-driver 'ticker 1000)
(send-message `(display "Hello! Enter your name:\n"))
(send-message `(request read-name read-line))
(send-message 'greet-loop)
(subscribe 'greet-loop-handler
(message-handlers w
['greet-loop
(transition w
(send-message `(display "Hello! Enter your name:\n"))
(send-message `(request read-name read-line)))]))
(subscribe 'ticker-handler
(message-handlers w
[`(tick ,counter ,_)
@ -50,12 +56,16 @@
`(display ,(string-append "TICK "
(number->string counter)
"\n"))))]))
(subscribe 'greet
(subscribe 'read-line-result-handler
(message-handlers w
[`(reply read-name ,(== eof))
(transition w
(send-message `(display "Goodbye!\n")))]
[`(reply read-name ,name)
(transition w
(send-message `(display "Hello, "))
(send-message `(display ,name))
(send-message `(display "!\n"))
(unsubscribe 'ticker)
(send-message 'greet-loop)
)])))