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

View file

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