Is there a haskell library function to monitor a file without polling?
With polling i would do someting like this:
monitor file mtime handler = do
threadDelay n -- sleep `n` ns
t <- getModificationTime file
if t > mtime
then handler >> monitor file t handler
else monitor file mtime handler
What I want is something like a blocking getModificationTime which will be woken up by the system. Is there something available?
I would be perfectly happy if it was available for posix systems only, but the more portable the better :-)
Edit: I know hinotify, but I'm on a Mac (that's why I mention POSIX).
inotify (short for inode notify) is a Linux kernel subsystem that notices changes in a file system (file/directory) and notifies those changes to applications. It is the base for many underlying command-line utilities that deal with file monitoring use-cases.
Inotify Watch helps to keep track of the file changes under the directories on “watch” and report back to the application in a standard format using the API calls. We can monitor multiple file events under the watched directory using the API calls.
The kqueue package should do this: http://hackage.haskell.org/package/kqueue
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With