unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Jan Wielkiewicz <tona_kosmicznego_smiecia@interia.pl>
To: guile-user@gnu.org
Subject: GOOPS and fibers - need help understanding what's wrong, bug in fibers/guile?
Date: Wed, 22 Jul 2020 01:56:53 +0200	[thread overview]
Message-ID: <20200722015653.630db7f9@interia.pl> (raw)

Hello,

I started writing my project in Guile with GOOPS and fibers (I'll
release it once it stops being a shame and starts working!), but I
encountered a problem:

The example from fibers' manual doesn't work:

(lambda ()
 (spawn-fiber (lambda () (display "hey!\n")))))

It doesn't print "hey" as documented in the manual.
I use guile 3.0.4 and fibers 1.0.0 (from Guix).

I also tried making a simple proof of concept, but it doesn't seem to
do anything. I would like to understand what's wrong with my code or
report a bug, if this is the case. No errors, warnings, syntax errors,
just silence.

My code:

(define-module (blocks block)
  #:use-module (fibers)
  #:use-module (fibers channels)
  #:use-module (oop goops)
  #:use-module (srfi srfi-9) ;; records
  #:export (<peer>
            connect-peers
            send-message
            handle-message
            start-listening))

(define-class <peer> ()
  (input #:init-form '() #:getter get-input
         #:setter set-input #:init-keyword #:input)
  (output #:init-form '() #:getter get-output
          #:setter set-output #:init-keyword #:output))

;; Only connection, no messaging started.
(define-method (connect-peers (p1 <peer>) (p2 <peer>))
  (let ((p1-p2 (make-channel)) ;; p1 to p2
        (p2-p1 (make-channel))) ;; p2 to p1
    (set-input p1 p2-p1)
    (set-output p1 p1-p2)
    (set-input p2 p1-p2)
    (set-output p2 p2-p1)))

(define-method (send-message (p <peer>) msg)
  (put-message (get-output p) msg))

(define-method (handle-message (p <peer>))
  (let loop ()
    (define msg (get-message (get-input p)))
    (match (pk msg)
           ('ping (send-message p 'pong)))
    (loop)))

(define-method (start-listening (p1 <peer>) (p2 <peer>))
  (run-fibers
   (lambda ()
     (spawn-fiber
      (lambda ()
        (connect-peers p1 p2)
        (handle-message p1)
        (send-message p1 'ping)
        (handle-message p2))))))

I run this in repl:

(define p1 (make <peer>))
(define p2 (make <peer>))

(start-listening p1 p2)


-----

Thanks in advance,
Jan Wielkiewicz



             reply	other threads:[~2020-07-21 23:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-21 23:56 Jan Wielkiewicz [this message]
2020-07-22 11:54 ` GOOPS and fibers - need help understanding what's wrong, bug in fibers/guile? Chris Vine
2020-07-22 12:28   ` Chris Vine
2020-07-24 16:19     ` Jan Wielkiewicz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200722015653.630db7f9@interia.pl \
    --to=tona_kosmicznego_smiecia@interia.pl \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).