1 ! Copyright (C) 2008, 2009 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.loader 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 hashcode* path>> hashcode* ;
27 M: monitor timeout timeout>> ;
29 M: monitor set-timeout (>>timeout) ;
31 : new-monitor ( path mailbox class -- monitor )
36 TUPLE: file-change path changed monitor ;
38 : queue-change ( path changes monitor -- )
40 [ [ file-change boa ] keep queue>> mailbox-put ] [ 3drop ] if ;
42 HOOK: (monitor) io-backend ( path recursive? mailbox -- monitor )
44 : <monitor> ( path recursive? -- monitor )
47 : next-change ( monitor -- change )
48 [ queue>> ] [ timeout ] bi mailbox-get-timeout ;
53 SYMBOL: +rename-file-old+
54 SYMBOL: +rename-file-new+
57 : with-monitor ( path recursive? quot -- )
58 [ <monitor> ] dip with-disposal ; inline
60 : run-monitor ( path recursive? quot -- )
61 '[ [ @ t ] loop ] with-monitor ; inline
64 { [ os macosx? ] [ "io.monitors.macosx" require ] }
65 { [ os linux? ] [ "io.monitors.linux" require ] }
66 { [ os winnt? ] [ "io.monitors.windows.nt" require ] }