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 17 18
:: Void = Void

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

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