initial commit
This commit is contained in:
commit
b4ad473f23
1 changed files with 46 additions and 0 deletions
46
goblins-echo.scm
Normal file
46
goblins-echo.scm
Normal file
|
@ -0,0 +1,46 @@
|
|||
(use-modules (goblins)
|
||||
(goblins vat)
|
||||
(goblins ocapn captp)
|
||||
(goblins ocapn ids)
|
||||
(goblins ocapn netlayer prelay-utils)
|
||||
(goblins ocapn netlayer prelay)
|
||||
(fibers conditions)
|
||||
(ice-9 match))
|
||||
|
||||
(define can-quit?
|
||||
(make-condition))
|
||||
|
||||
(define echo-vat
|
||||
(spawn-vat #:name "echo-vat"))
|
||||
|
||||
(define (^listener bcom)
|
||||
(lambda (text) (format #t "~a\n" text)))
|
||||
|
||||
(define (listen setup-sref)
|
||||
(with-vat echo-vat
|
||||
(on (fetch-and-spawn-prelay-netlayer setup-sref)
|
||||
(lambda (netlayer)
|
||||
(define mycapn (spawn-mycapn netlayer))
|
||||
(define listener (spawn ^listener))
|
||||
(define listener-id ($ mycapn 'register listener 'prelay))
|
||||
(format #t "Listener registered at ~s\n" (ocapn-id->string listener-id))))))
|
||||
|
||||
(define (say setup-sref listener-sref text)
|
||||
(with-vat echo-vat
|
||||
(on (fetch-and-spawn-prelay-netlayer setup-sref)
|
||||
(lambda (netlayer)
|
||||
(on (<- (<- (spawn-mycapn netlayer) 'enliven listener-sref) text)
|
||||
(lambda (_)
|
||||
(format #t "sent message ~s.\n" text)
|
||||
(signal-condition! can-quit?)))))))
|
||||
|
||||
(match (command-line)
|
||||
[(_cmd "listen" setup-id)
|
||||
(listen (string->ocapn-id setup-id))]
|
||||
[(_cmd "say" setup-id listener-id text)
|
||||
(say (string->ocapn-id setup-id) (string->ocapn-id listener-id) text)]
|
||||
[unknown-cmd
|
||||
(format #t "Unknown command ~a\n" unknown-cmd)
|
||||
(signal-condition! can-quit?)])
|
||||
|
||||
(wait can-quit?)
|
Loading…
Reference in a new issue