Welcome to the CHICKEN Scheme pasting service

FIFO & threads added by mario-goulart on Tue May 20 22:58:45 2014

(use posix srfi-18)
(use stty)

(define fifo "a-fifo")
(delete-file* fifo)
(create-fifo fifo)

(define (fifo-reader)
  (thread-start!
   (lambda ()
     (let* ((fifo-fd (file-open fifo open/nonblock))
            (fifo-port (open-input-file* fifo-fd)))
       (print "reader: Got fifo port")
       (let loop ()
         (thread-wait-for-i/o! fifo-fd #:input)
         (let ((char (read-char fifo-port)))
           (print "Got char: " char)
           (flush-output))
         (loop))))))

(define (fifo-writer)
  (thread-start!
   (lambda ()
     (let ((fifo-port (open-output-file fifo)))
       (print "writer: Got fifo port")
       (let loop ()
         (with-stty '(not icanon)
           (lambda ()
             (thread-wait-for-i/o! fileno/stdin #:input)
             (display (read-char) fifo-port)
             (newline)))
         (flush-output fifo-port)
         (loop))))))

(fifo-reader)
(thread-join! (fifo-writer))

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
Which backend storage does qwiki use?
Visually impaired? Let me spell it for you (wav file) download WAV