newlisp/examples/observer

23 lines
425 B
Text
Raw Permalink Normal View History

2016-06-11 17:22:37 +00:00
#!/usr/bin/env newlisp
(define (count-down-proc x channel)
(while (!= x 0)
(write-line channel (string x))
(dec x)))
(define (observer-proc channel)
(do-until (= i "1")
(println "process " (setq i (read-line channel)))))
(map set '(in out) (pipe))
(set 'observer (fork (observer-proc in)))
(set 'counter (fork (count-down-proc 5 out)))
; avoid zombies
(wait-pid observer)
(wait-pid counter)
(exit)