unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* repl-server from fibers task
@ 2022-12-19 21:30 Matt Wette
  2022-12-21 15:43 ` Matt Wette
  0 siblings, 1 reply; 2+ messages in thread
From: Matt Wette @ 2022-12-19 21:30 UTC (permalink / raw)
  To: Guile User

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 ---




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: repl-server from fibers task
  2022-12-19 21:30 repl-server from fibers task Matt Wette
@ 2022-12-21 15:43 ` Matt Wette
  0 siblings, 0 replies; 2+ messages in thread
From: Matt Wette @ 2022-12-21 15:43 UTC (permalink / raw)
  To: guile-user

On 12/19/22 1:30 PM, Matt Wette wrote:
> 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
I got something to work:

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

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

(use-modules ((fibers) #:renamer (lambda (s) (if (eq? s 'sleep) 'fsleep 
s))))
(use-modules (fibers scheduler))
(use-modules (system repl server))
(use-modules (system repl coop-server))

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

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

(define (monitor)
   (let* ((server (spawn-coop-repl-server)))
     (let loop ()
       (poll-coop-repl-server server)
       (yield-current-task)
       (loop))))

(run-fibers
  (lambda ()
    (spawn-fiber task1)
    (spawn-fiber monitor)
    (fsleep 30))
  #:hz 0 #:install-suspendable-ports? #f)

;;; --- last line ---




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-21 15:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-19 21:30 repl-server from fibers task Matt Wette
2022-12-21 15:43 ` Matt Wette

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).