Okay this was annoying. IO is blocking by default and it's not obvious. Working again.
This commit is contained in:
parent
6ac6534635
commit
ba3650e87b
2 changed files with 8 additions and 6 deletions
|
@ -20,9 +20,7 @@
|
|||
((board-winner? board peer-mark) 'lost)
|
||||
(else 'play)))
|
||||
(define (signal-turn)
|
||||
(format #t "signal-turn start\n")
|
||||
(syscaller-free-fiber (λ () (put-message state+ (%state))))
|
||||
(format #t "signal-turn end\n")
|
||||
#f)
|
||||
(define (switch-turn!)
|
||||
(let ((new-turn (not ($ %my-turn?))))
|
||||
|
@ -36,8 +34,7 @@
|
|||
(if (not ($ %my-turn?))
|
||||
(begin
|
||||
(board-choose! board peer-mark x y)
|
||||
(switch-turn!)
|
||||
(format #t "I have logged the peer's turn.\n"))
|
||||
(switch-turn!))
|
||||
(error "It's my turn!"))]
|
||||
;; TODO: These need to go somewhere else so the peer can't move or init for us!
|
||||
[(try-transition) 'playing]
|
||||
|
@ -54,10 +51,8 @@
|
|||
(if ($ %my-turn?)
|
||||
(begin
|
||||
(board-assert-vacant board x y)
|
||||
(format #t "tell peer about it\n")
|
||||
(on (<- peer 'peer-turn! x y)
|
||||
(λ (_)
|
||||
(format #t "peer promise resolve, then switch and return\n")
|
||||
(board-choose! board mark x y)
|
||||
(switch-turn!)
|
||||
(%state))
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#:use-module (gib-gab-gob board)
|
||||
#:use-module (ice-9 rdelim)
|
||||
#:use-module (ice-9 exceptions)
|
||||
#:use-module (ice-9 suspendable-ports)
|
||||
#:use-module (srfi srfi-9)
|
||||
#:use-module (srfi srfi-1)
|
||||
#:use-module (fibers)
|
||||
|
@ -15,6 +16,12 @@
|
|||
#:use-module (goblins ocapn netlayer onion)
|
||||
#: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)
|
||||
|
||||
;; Module for simple console-based UI (no curses)
|
||||
|
|
Loading…
Reference in a new issue