commit b4ad473f2332525721dd451643228635fbacd968 Author: Vivianne Langdon Date: Mon Jan 29 15:07:18 2024 -0500 initial commit diff --git a/goblins-echo.scm b/goblins-echo.scm new file mode 100644 index 0000000..6205082 --- /dev/null +++ b/goblins-echo.scm @@ -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?)