Okay this was annoying. IO is blocking by default and it's not obvious. Working again.

This commit is contained in:
Vivianne 2023-07-16 21:32:21 -07:00
parent 6ac6534635
commit ba3650e87b
2 changed files with 8 additions and 6 deletions

View File

@ -20,9 +20,7 @@
((board-winner? board peer-mark) 'lost) ((board-winner? board peer-mark) 'lost)
(else 'play))) (else 'play)))
(define (signal-turn) (define (signal-turn)
(format #t "signal-turn start\n")
(syscaller-free-fiber (λ () (put-message state+ (%state)))) (syscaller-free-fiber (λ () (put-message state+ (%state))))
(format #t "signal-turn end\n")
#f) #f)
(define (switch-turn!) (define (switch-turn!)
(let ((new-turn (not ($ %my-turn?)))) (let ((new-turn (not ($ %my-turn?))))
@ -36,8 +34,7 @@
(if (not ($ %my-turn?)) (if (not ($ %my-turn?))
(begin (begin
(board-choose! board peer-mark x y) (board-choose! board peer-mark x y)
(switch-turn!) (switch-turn!))
(format #t "I have logged the peer's turn.\n"))
(error "It's my turn!"))] (error "It's my turn!"))]
;; TODO: These need to go somewhere else so the peer can't move or init for us! ;; TODO: These need to go somewhere else so the peer can't move or init for us!
[(try-transition) 'playing] [(try-transition) 'playing]
@ -54,10 +51,8 @@
(if ($ %my-turn?) (if ($ %my-turn?)
(begin (begin
(board-assert-vacant board x y) (board-assert-vacant board x y)
(format #t "tell peer about it\n")
(on (<- peer 'peer-turn! x y) (on (<- peer 'peer-turn! x y)
(λ (_) (λ (_)
(format #t "peer promise resolve, then switch and return\n")
(board-choose! board mark x y) (board-choose! board mark x y)
(switch-turn!) (switch-turn!)
(%state)) (%state))

View File

@ -4,6 +4,7 @@
#:use-module (gib-gab-gob board) #:use-module (gib-gab-gob board)
#:use-module (ice-9 rdelim) #:use-module (ice-9 rdelim)
#:use-module (ice-9 exceptions) #:use-module (ice-9 exceptions)
#:use-module (ice-9 suspendable-ports)
#:use-module (srfi srfi-9) #:use-module (srfi srfi-9)
#:use-module (srfi srfi-1) #:use-module (srfi srfi-1)
#:use-module (fibers) #:use-module (fibers)
@ -15,6 +16,12 @@
#:use-module (goblins ocapn netlayer onion) #:use-module (goblins ocapn netlayer onion)
#:export (make-initiator make-joiner)) #:export (make-initiator make-joiner))
;; https://www.gnu.org/software/guile/manual/guile.html#Non_002dBlocking-I_002fO
(let* ((input (current-input-port))
(flags (fcntl input F_GETFL)))
(fcntl input F_SETFL (logior O_NONBLOCK flags)))
(install-suspendable-ports!)
(random-state-from-platform) (random-state-from-platform)
;; Module for simple console-based UI (no curses) ;; Module for simple console-based UI (no curses)