1 ! Copyright (C) 2008 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
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 < identity-tuple 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 : queue-change ( path changes monitor -- )
38 [ [ 3array ] keep queue>> mailbox-put ] [ 3drop ] if ;
40 HOOK: (monitor) io-backend ( path recursive? mailbox -- monitor )
42 : <monitor> ( path recursive? -- monitor )
45 : next-change ( monitor -- path changed )
46 [ queue>> ] [ timeout ] bi mailbox-get-timeout first2 ;
51 SYMBOL: +rename-file-old+
52 SYMBOL: +rename-file-new+
55 : with-monitor ( path recursive? quot -- )
56 [ <monitor> ] dip with-disposal ; inline
59 { [ os macosx? ] [ "io.monitors.macosx" require ] }
60 { [ os linux? ] [ "io.monitors.linux" require ] }
61 { [ os winnt? ] [ "io.monitors.windows.nt" require ] }