Update with new api
This commit is contained in:
parent
b4ad473f23
commit
d8731c1104
1 changed files with 24 additions and 7 deletions
|
@ -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)))
|
||||||
|
|
||||||
|
;; 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)
|
||||||
|
(spawn ^mycapn-registry netlayer 'prelay))
|
||||||
|
#:promise? #t))
|
||||||
|
;; end proposal
|
||||||
|
|
||||||
(define (listen setup-sref)
|
(define (listen setup-sref)
|
||||||
(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)
|
||||||
(define mycapn (spawn-mycapn netlayer))
|
|
||||||
(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?)))))))
|
||||||
|
|
Loading…
Reference in a new issue