I would like to render a display based on objects on other vats, but I’m having trouble causing a sequence of prints. Suppose I generate some playing cards in some vat hosting a card game, and provide some views into the card which let you look at the card, but not peek at it (some cards are hidden and others revealed):
(use-modules (goblins)
(goblins actor-lib facet)
(goblins actor-lib joiners)
(goblins actor-lib methods))
(define* (^card bcom suit number #:optional (hidden #f))
(methods
((peek-suit) suit)
((look-suit) (if hidden '* suit))
((peek-number) number)
((look-number) (if hidden -1 number))))
(define card-views (with-vat (spawn-vat)
(map (lambda (card)
(spawn ^facet card
'look-suit 'look-number))
(list (spawn ^card '♠ 3 #f)
(spawn ^card '♥ 3 #t)
(spawn ^card '♣ 3 #f)))))
Naively, if you wanted to print the suits of the cards, you would do something like this:
(with-vat (spawn-vat)
(display "first line\n")
(on (all-of* (map (lambda (card) (<- card 'look-suit))
card-views))
(lambda (suits)
(display (string-join (map symbol->string
suits)))
(newline)))
(display "third line\n"))
But this does’t work, simply printing “first line\nthird line\n”. I would like to halt execution until the cards print with (make-condition) like so:
(use-modules (fibers conditions)
(fibers operations))
(with-vat (spawn-vat)
(display "first line\n")
(let ((printed-second-line? (make-condition)))
(on (all-of* (map (lambda (card) (<- card 'look-suit))
card-views))
(lambda (suits)
(pk suits)
(display (string-join (map symbol->string
suits)))
(pk "displayed cards")
(newline)
(signal-condition! printed-second-line?)))
(perform-operation (wait-operation printed-second-line?)))
(display "third line\n"))
but execution hangs on (perform-operation ...)
. I got signal-condition!
, perform-operation
, and wait-operation
from Example Greeters over CapTP via Tor (Spritely Goblins). However, I have not seen those used elsewhere.
Is there a different way I should be doing this?