blob: 75cc04badd7b47c1923a2f0706b86d0a98a0aa3f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
module test
import StdFile
import Data.Either
import Data.Maybe
import Inotify
:: 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.
*/
Start w
# (Just inot) = inotify_init Void
# (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
# (io,w) = stdio w
# io = io <<< "You have 10 seconds to do something with file1 or file2\n"
# (ok,w) = fclose io w
# (inot, w) = inotify_loop_with_timeout (Just 10000) inot w
= inotify_close inot
where
echo :: String INEvent (Maybe String) Void *World -> *(Void, *World)
echo fname ev f _ w
# (io,w) = stdio w
# io = io <<< "EVENT: ["<<< fname <<<"; "<<< ev <<<"; "<<< f <<<"]\n"
# (ok,w) = fclose io w
= (Void, w)
instance <<< (Maybe a) | <<< a
where
(<<<) f Nothing = f
(<<<) f (Just x) = f <<< x
|