Switch to using a channel as a signal is a one-time. working!

This commit is contained in:
Vivianne 2023-07-09 22:03:21 -07:00
parent 78226e84e6
commit ad2d33e994
2 changed files with 10 additions and 6 deletions

View File

@ -1,5 +1,6 @@
(define-module (gib-gab-gob game)
#:use-module (fibers conditions)
#:use-module (fibers)
#:use-module (fibers channels)
#:use-module (goblins)
#:use-module (goblins actor-lib methods)
#:use-module (goblins actor-lib sealers)
@ -16,10 +17,14 @@
((board-winner? board mark) => 'won)
((board-winner? board peer-mark) => 'lost)
(else 'play)))
(define (signal-turn)
;; any better way to do this?
(spawn-fiber (λ () (put-message my-turn+ #t))))
(define (switch-turn!)
(set! %my-turn? (not %my-turn?))
(when %my-turn? (signal-condition! my-turn+)))
(when first? (signal-condition! my-turn+))
(when %my-turn? (signal-turn))
#f)
(when first? (signal-turn))
(methods
;; The peer is telling us about the turn it took.
[(peer-turn! x y)

View File

@ -8,7 +8,6 @@
#:use-module (srfi srfi-1)
#:use-module (fibers)
#:use-module (fibers channels)
#:use-module (fibers conditions)
#:use-module (goblins)
#:export (make-initiator))
@ -16,7 +15,7 @@
;; A single run of the loop for a bespoke REPL for playing the game
(define (%loop vat b controller my-turn+)
(wait my-turn+)
(get-message my-turn+)
(with-vat vat
(on (<- controller 'state)
(λ (state)
@ -66,7 +65,7 @@
(define (make-initiator)
(with-vat
(spawn-vat #:name "Initiator Game")
(define my-turn+ (make-condition))
(define my-turn+ (make-channel))
(define board (make-board))
(define initiator (spawn ^game-initiator ^ggg-controller board my-turn+))
(initiator/connect initiator)