Search code examples
haskellpollinginotifybusy-waiting

Haskell: Monitor a file without polling (à la inotify in linux)


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).


Solution

  • The kqueue package should do this: http://hackage.haskell.org/package/kqueue