test.icl 1.03 KB
Newer Older
Camil Staps's avatar
Camil Staps committed
1 2 3 4 5 6 7
module test

import StdFile
import Data.Either
import Data.Maybe
import Inotify

8 9 10 11 12 13 14 15 16
/**
 * test: Example usage of Inotify
 *
 * This will show all events on files file1 and file2. They should exist before
 * starting this program.
 *
 * When nothing has happened for 10s, the program will exit.
 */

Camil Staps's avatar
Camil Staps committed
17
Start w
Camil Staps's avatar
Camil Staps committed
18
# (Just inot) = inotify_init ()
Camil Staps's avatar
Camil Staps committed
19 20 21 22
# (Right watch, inot)
	= inotify_add_watch (echo "file1") IN_ALL_EVENTS "file1" inot
# (Right watch, inot)
	= inotify_add_watch (echo "file2") IN_ALL_EVENTS "file2" inot
23
# (io,w)      = stdio w
24
# io = io   <<< "You have 10 seconds to do something with file1 or file2\n"
25
# (ok,w)      = fclose io w
26
# (inot, w)   = inotify_loop_with_timeout (Just 10000) inot w
Camil Staps's avatar
Camil Staps committed
27 28
= inotify_close inot
where
29 30
	echo :: String INEvent (Maybe String) *(Inotify ()) *World -> *(*Inotify (), *World)
	echo fname ev f st w
31 32 33
		# (io,w)    = stdio w
		# io = io <<< "EVENT: ["<<< fname <<<"; "<<< ev <<<"; "<<< f <<<"]\n"
		# (ok,w)    = fclose io w
34
		= (st, w)
35 36 37 38 39

instance <<< (Maybe a) | <<< a
where
	(<<<) f Nothing  = f
	(<<<) f (Just x) = f <<< x