File system change monitors

File system change monitors listen for changes to file names, attributes and contents under a specified directory. They can optionally be recursive, in which case subdirectories are also monitored.

Monitoring operations must be wrapped in a combinator:
with-monitors ( quot -- )

Creating a file system change monitor and listening for changes:
<monitor> ( path recursive? -- monitor )

next-change ( monitor -- change )

An alternative programming style is where instead of having a thread listen for changes on a monitor, change notifications are posted to a mailbox:
(monitor) ( path recursive? mailbox -- monitor )

File system change descriptors
Monitors on different platforms

Monitors are closed by calling dispose or with-disposal. An easy way to pair construction with disposal is to use a combinator:
with-monitor ( path recursive? quot -- )

Monitors support the I/O timeout protocol.

An example which watches a directory for changes:
USE: io.monitors : watch-loop ( monitor -- ) dup next-change path>> print flush watch-loop ; : watch-directory ( path -- ) [ t [ watch-loop ] with-monitor ] with-monitors ;