initial commit

This commit is contained in:
Peter Tillemans 2025-01-29 09:06:47 +01:00
commit 033d2c2dd9

26
inotify-test.scm Normal file
View file

@ -0,0 +1,26 @@
(use-modules (rnrs io ports))
(use-modules (ice-9 threads))
(define (on-file-change fname thunk)
(let* ((input+output (pipe))
(pid (spawn "inotifywait" `("inotifywait" "-m" ,fname)
#:output (cdr input+output))))
(close-port (cdr input+output))
(let loop ((line "dummy CLOSE_WRITE"))
(unless (eof-object? line)
(format #t "read ~s~%" line)
(if (string-contains line "CLOSE_WRITE")
(thunk))
(loop (get-line (car input+output)))))
(close-port (car input+output))
(waitpid pid)))
(call-with-new-thread (lambda () (on-file-change "inotify-test.scm" (lambda () (format #t "file changed~%")))))
(format #t "waiting 30s for file change~%")
(do ((i 0 (+ i 1))) ((> i 30) (format #t "done loop~%"))
(sleep 1)
(format #t "tick~%"))
(format #t "done waiting~%")