factor/extra/io/monitors/monitors.factor

52 lines
1.4 KiB
Factor
Raw Normal View History

! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: io.backend kernel continuations namespaces sequences
2008-04-11 08:15:26 -04:00
assocs hashtables sorting arrays threads boxes io.timeouts
accessors concurrency.mailboxes ;
IN: io.monitors
2008-04-11 08:15:26 -04:00
HOOK: init-monitors io-backend ( -- )
2008-04-11 08:15:26 -04:00
HOOK: dispose-monitors io-backend ( -- )
2008-04-11 08:15:26 -04:00
: with-monitors ( quot -- )
[
init-monitors
[ dispose-monitors ] [ ] cleanup
] with-scope ; inline
2008-04-11 08:15:26 -04:00
TUPLE: monitor < identity-tuple path queue timeout ;
2008-04-11 08:15:26 -04:00
M: monitor hashcode* path>> hashcode* ;
2008-04-11 08:15:26 -04:00
M: monitor timeout timeout>> ;
2008-04-11 08:15:26 -04:00
M: monitor set-timeout (>>timeout) ;
2008-04-11 08:15:26 -04:00
: construct-monitor ( path mailbox class -- monitor )
construct-empty
swap >>queue
swap >>path ; inline
2008-04-11 08:15:26 -04:00
: queue-change ( path changes monitor -- )
2008-04-11 09:35:21 -04:00
3dup and and
[ [ 3array ] keep queue>> mailbox-put ] [ 3drop ] if ;
2008-04-11 08:15:26 -04:00
HOOK: (monitor) io-backend ( path recursive? mailbox -- monitor )
2008-04-11 08:15:26 -04:00
: <monitor> ( path recursive? -- monitor )
<mailbox> (monitor) ;
: next-change ( monitor -- path changed )
2008-04-11 08:15:26 -04:00
[ queue>> ] [ timeout ] bi mailbox-get-timeout first2 ;
SYMBOL: +add-file+
SYMBOL: +remove-file+
SYMBOL: +modify-file+
2008-04-11 08:15:26 -04:00
SYMBOL: +rename-file-old+
SYMBOL: +rename-file-new+
2008-04-11 10:54:50 -04:00
SYMBOL: +rename-file+
: with-monitor ( path recursive? quot -- )
>r <monitor> r> with-disposal ; inline