syndicate-2017/racket/typed/examples/roles/ping-pong.rkt

21 lines
499 B
Racket
Raw Normal View History

2018-07-31 18:46:36 +00:00
#lang typed/syndicate/roles
;; Expected Output
;; pong: 8339
(define-type-alias ds-type
2018-09-12 21:03:19 +00:00
(U (Message (Tuple String Int))
2018-07-31 18:46:36 +00:00
(Observe (Tuple String ★/t))))
(run-ground-dataspace ds-type
2018-07-31 18:46:36 +00:00
(spawn ds-type
(start-facet echo
2018-09-12 21:03:19 +00:00
(on (message (tuple "ping" (bind x Int)))
(send! (tuple "pong" x)))))
2018-07-31 18:46:36 +00:00
(spawn ds-type
(start-facet serve
2018-09-12 21:03:19 +00:00
(on start
(send! (tuple "ping" 8339)))
(on (message (tuple "pong" (bind x Int)))
(printf "pong: ~v\n" x)))))