Hi all,
I just released Fibers 0.1.0. Fibers is an experimental facility for
Erlang-like concurrency in Guile 2.2.
As an example, here is a ping server written in Fibers:
(define (socket-loop socket store)
(let loop ()
(match (accept socket)
((client . addr)
(set-nonblocking! client)
;; Disable Nagle's algorithm. We buffer ourselves.
(setsockopt client IPPROTO_TCP TCP_NODELAY 0)
(spawn (lambda () (client-loop client addr store)))
(loop)))))
As you can see it's straightforward in style. For each client that
comes in, we spawn a fiber to handle the client. Here's the fiber that
handles the client:
(define (client-loop port addr store)
(let loop ()
(let ((line (read-line port)))
(cond
((eof-object? line)
(close-port port))
(else
(put-string port line)
(put-char port #\newline)
(force-output port)
(loop))))))