#!/bin/sh #| -*- scheme -*- exec csi -s $0 "$@" |# (use posix srfi-18) (define (async-process thunk) (receive (in out) (create-pipe) (process-fork (lambda () (file-close in) (thunk) (file-close out))) (file-close out) in)) (define (wait fd) (thread-start! (lambda () (thread-wait-for-i/o! fd) (file-close fd)))) (define proc1 (async-process (lambda () (print "Hi from proc1") (system "sleep 5") (print "proc1 done sleeping 5 secs")))) (define proc2 (async-process (lambda () (print "Hi from proc2") (system "sleep 2") (print "proc2 done sleeping 2 sec")))) (define (mainloop) (let ((t1 (wait proc1)) (t2 (wait proc2))) (let loop () (print "--") (thread-sleep! 0.9) (loop)))) (mainloop)