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)
|
||||
(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)))
|
||||
|
||||
;; 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)
|
||||
(with-vat echo-vat
|
||||
(on (fetch-and-spawn-prelay-netlayer setup-sref)
|
||||
(lambda (netlayer)
|
||||
(define mycapn (spawn-mycapn netlayer))
|
||||
(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?)))))))
|
||||
|
|
Loading…
Reference in a new issue