initial commit
This commit is contained in:
commit
033d2c2dd9
1 changed files with 26 additions and 0 deletions
26
inotify-test.scm
Normal file
26
inotify-test.scm
Normal 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~%")
|
||||
|
Loading…
Add table
Reference in a new issue