mini-echo examples

This commit is contained in:
Tony Garnock-Jones 2016-01-14 15:19:00 -05:00
parent 31fe2cd92b
commit 6058f8ec6e
2 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,23 @@
#lang prospect
(require prospect/actor)
(struct echo-req (body) #:prefab)
(struct echo-resp (body) #:prefab)
(actor-body->spawn-action
(lambda ()
(actor (forever #:collect [(count 0)]
(on (message (echo-req $body))
(send! (echo-resp body))
(+ count 1))))
(actor (forever (on (message (echo-resp $body))
(printf "Received: ~v\n" body))))
(until (asserted (observe (echo-req _))))
(until (asserted (observe (echo-resp _))))
(send! (echo-req 0))
(send! (echo-req 1))
(send! (echo-req 2))
))

View File

@ -0,0 +1,25 @@
#lang prospect
(struct echo-req (body) #:prefab)
(struct echo-resp (body) #:prefab)
(spawn (lambda (e count)
(match e
[(message (echo-req body))
(transition (+ count 1)
(message (echo-resp body)))]
[_ #f]))
0
(sub (echo-req ?)))
(spawn (lambda (e s)
(match e
[(message (echo-resp body))
(printf "Received: ~v\n" body)
#f]
[_ #f]))
(void)
(list (sub (echo-resp ?))
(message (echo-req 0))
(message (echo-req 1))
(message (echo-req 2))))