1 ! Copyright (C) 2008, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: io.backend kernel continuations destructors namespaces
4 sequences assocs hashtables sorting arrays threads boxes
5 io.timeouts accessors concurrency.mailboxes fry
6 system vocabs combinators ;
9 HOOK: init-monitors io-backend ( -- )
11 M: object init-monitors ;
13 HOOK: dispose-monitors io-backend ( -- )
15 M: object dispose-monitors ;
17 : with-monitors ( quot -- )
20 [ dispose-monitors ] [ ] cleanup
23 TUPLE: monitor < disposable path queue timeout ;
25 M: monitor timeout timeout>> ;
27 M: monitor set-timeout timeout<< ;
31 SYMBOL: monitor-disposed
36 [ monitor-disposed ] dip queue>> mailbox-put ;
38 : new-monitor ( path mailbox class -- monitor )
43 TUPLE: file-change path changed monitor ;
45 : queue-change ( path changes monitor -- )
47 [ check-disposed ] keep
48 [ file-change boa ] keep
52 HOOK: (monitor) io-backend ( path recursive? mailbox -- monitor )
54 : <monitor> ( path recursive? -- monitor )
57 : next-change ( monitor -- change )
60 [ ] [ queue>> ] [ timeout ] tri mailbox-get-timeout
61 dup monitor-disposed eq? [ drop already-disposed ] [ nip ] if
67 SYMBOL: +rename-file-old+
68 SYMBOL: +rename-file-new+
71 : with-monitor ( path recursive? quot -- )
72 [ <monitor> ] dip with-disposal ; inline
74 : run-monitor ( path recursive? quot -- )
75 '[ [ @ t ] loop ] with-monitor ; inline
78 { [ os macosx? ] [ "io.monitors.macosx" require ] }
79 { [ os linux? ] [ "io.monitors.linux" require ] }
80 { [ os windows? ] [ "io.monitors.windows" require ] }