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) (use-modules (goblins)
(goblins actor-lib methods)
(goblins vat) (goblins vat)
(goblins ocapn captp) (goblins ocapn captp)
(goblins ocapn ids) (goblins ocapn ids)
@ -16,20 +17,36 @@
(define (^listener bcom) (define (^listener bcom)
(lambda (text) (format #t "~a\n" text))) (lambda (text) (format #t "~a\n" text)))
(define (listen setup-sref) ;; Proposal for a registry object that bundles up a netlayer and mycapn into a single two-method capability
(with-vat echo-vat ;; 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) (on (fetch-and-spawn-prelay-netlayer setup-sref)
(lambda (netlayer) (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 (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)))))) (format #t "Listener registered at ~s\n" (ocapn-id->string listener-id))))))
(define (say setup-sref listener-sref text) (define (say setup-sref listener-sref text)
(with-vat echo-vat (with-vat echo-vat
(on (fetch-and-spawn-prelay-netlayer setup-sref) (on (prelay-sref->mycapn-registry setup-sref)
(lambda (netlayer) (lambda (registry)
(on (<- (<- (spawn-mycapn netlayer) 'enliven listener-sref) text) (on (<- (<- registry 'enliven listener-sref) text)
(lambda (_) (lambda (_)
(format #t "sent message ~s.\n" text) (format #t "sent message ~s.\n" text)
(signal-condition! can-quit?))))))) (signal-condition! can-quit?)))))))