Update with new api

This commit is contained in:
Vivianne 2024-01-29 17:20:51 -05:00
parent b4ad473f23
commit d8731c1104

View file

@ -1,4 +1,5 @@
(use-modules (goblins)
(goblins actor-lib methods)
(goblins vat)
(goblins ocapn captp)
(goblins ocapn ids)
@ -16,20 +17,36 @@
(define (^listener bcom)
(lambda (text) (format #t "~a\n" text)))
(define (listen setup-sref)
(with-vat echo-vat
;; Proposal for a registry object that bundles up a netlayer and mycapn into a single two-method capability
;; See https://community.spritely.institute/t/feedback-on-ocapn-netlayers-interface/407
(define (^mycapn-registry bcom netlayer netlayer-type)
(define mycapn (spawn-mycapn netlayer))
(methods
[(register obj)
($ mycapn 'register obj netlayer-type)]
[(enliven id)
($ mycapn 'enliven id)]))
(define (prelay-sref->mycapn-registry setup-sref)
(on (fetch-and-spawn-prelay-netlayer setup-sref)
(lambda (netlayer)
(define mycapn (spawn-mycapn netlayer))
(spawn ^mycapn-registry netlayer 'prelay))
#:promise? #t))
;; end proposal
(define (listen setup-sref)
(with-vat echo-vat
(on (prelay-sref->mycapn-registry setup-sref)
(lambda (registry)
(define listener (spawn ^listener))
(define listener-id ($ mycapn 'register listener 'prelay))
(define listener-id ($ registry 'register listener))
(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)
(on (prelay-sref->mycapn-registry setup-sref)
(lambda (registry)
(on (<- (<- registry 'enliven listener-sref) text)
(lambda (_)
(format #t "sent message ~s.\n" text)
(signal-condition! can-quit?)))))))