guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

repl-server from fibers task


From: Matt Wette
Subject: repl-server from fibers task
Date: Mon, 19 Dec 2022 13:30:32 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2

Hi All,

I'm trying to get fibers to run in "pure asynchronous" style with a repl-server. By "pure asynchronous" style I mean #:hz 0 and possibly #:suspendable-ports #f. My only guess is that maybe the repl-server has a continuation barrier in the way.

Either the other task runs, and I get no connection to the repl-server, or vice versa.

Anyone here gotten this to work?  If the code worked below the main terminal
would be counting along while one could telnet in from another source and use the repl.

Any help appreciated.

Matt

#!/usr/bin/env guile
# -*- scheme -*-
!#

;; connect to monitor via
;;   $ telnet localhost 37146

(use-modules (fibers))
(use-modules (fibers scheduler))
(use-modules (system repl server))

(define (sf fmt . args) (apply simple-format #t fmt args))

(define (task1)
  (let loop ((cnt 0))
    (sleep 1)
    (sf "task1: ~S\n" cnt)
    (loop (1+ cnt))))

(define monitor
  (let ((sock (make-tcp-server-socket)))
    (fcntl sock F_SETFL (logior O_NONBLOCK (fcntl sock F_GETFL)))
    (add-hook! before-read-hook (lambda () (yield-current-task)))
    (lambda () (run-server sock))))

(run-fibers
 (lambda ()
   (spawn-fiber task1)
   (spawn-fiber monitor)
   (sleep 30))
 #:scheduler (make-scheduler #:parallelism 2)
 #:hz 0
 #:install-suspendable-ports? #f)

;;; --- last line ---




reply via email to

[Prev in Thread] Current Thread [Next in Thread]