;; the previous workarounds won't block while waiting for the first byte, but will block other srfi-18 threads after that. let's make a new port which never blocks instead! ;; don't block while reading anything from port p. port p must have an ;; associated filedescriptor. (define (make-nonblocking-input-port p) (make-input-port (lambda () (thread-wait-for-i/o! (port->fileno p)) (read-char p)) (lambda () (char-ready? p)) (lambda () (close-input-port p)))) (begin (print "begin " (current-milliseconds)) (thread-start! (lambda () (pp (call-with-input-pipe "sleep 1; echo a ; sleep 1 ; echo b" (o (lambda (p) (read-string #f p)) make-nonblocking-input-port))))) (thread-yield!) (print "end " (current-milliseconds)))