Safe Haskell | None |
---|
Minimal example:
{-# LANGUAGE OverloadedStrings #-} -- for FilePath literals import System.FSNotify import Control.Concurrent (threadDelay) import Control.Monad (forever) main = withManager $ \mgr -> do -- start a watching job (in the background) watchDir mgr -- manager "." -- directory to watch (const True) -- predicate print -- action -- sleep forever (until interrupted) forever $ threadDelay maxBound
- data Event
- type EventChannel = Chan Event
- eventTime :: Event -> UTCTime
- eventPath :: Event -> FilePath
- type Action = Event -> IO ()
- type ActionPredicate = Event -> Bool
- data WatchManager
- withManager :: (WatchManager -> IO a) -> IO a
- startManager :: IO WatchManager
- stopManager :: WatchManager -> IO ()
- defaultConfig :: WatchConfig
- data WatchConfig = WatchConfig {}
- data Debounce
- withManagerConf :: WatchConfig -> (WatchManager -> IO a) -> IO a
- startManagerConf :: WatchConfig -> IO WatchManager
- type StopListening = IO ()
- isPollingManager :: WatchManager -> Bool
- watchDir :: WatchManager -> FilePath -> ActionPredicate -> Action -> IO StopListening
- watchDirChan :: WatchManager -> FilePath -> ActionPredicate -> EventChannel -> IO StopListening
- watchTree :: WatchManager -> FilePath -> ActionPredicate -> Action -> IO StopListening
- watchTreeChan :: WatchManager -> FilePath -> ActionPredicate -> EventChannel -> IO StopListening
Events
A file event reported by a file watcher. Each event contains the canonical path for the file and a timestamp guaranteed to be after the event occurred (timestamps represent current time when FSEvents receives it from the OS and/or platform-specific Haskell modules).
type EventChannel = Chan EventSource
type ActionPredicate = Event -> BoolSource
A predicate used to determine whether to act on an event.
Starting/Stopping
data WatchManager Source
Watch manager. You need one in order to create watching jobs.
withManager :: (WatchManager -> IO a) -> IO aSource
Perform an IO action with a WatchManager in place. Tear down the WatchManager after the action is complete.
startManager :: IO WatchManagerSource
Start a file watch manager.
Directories can only be watched when they are managed by a started watch
watch manager.
When finished watching. you must release resources via stopManager
.
It is preferrable if possible to use withManager
to handle this
automatically.
stopManager :: WatchManager -> IO ()Source
Stop a file watch manager. Stopping a watch manager will immediately stop watching for files and free resources.
defaultConfig :: WatchConfigSource
Default configuration
data WatchConfig Source
Watch configuration
WatchConfig | |
|
This specifies whether events close to each other should be collapsed together, and how close is close enough.
DebounceDefault | perform debouncing based on the default time interval |
Debounce NominalDiffTime | perform debouncing based on the specified time interval |
NoDebounce | do not perform debouncing |
withManagerConf :: WatchConfig -> (WatchManager -> IO a) -> IO aSource
Like withManager
, but configurable
startManagerConf :: WatchConfig -> IO WatchManagerSource
Like startManager
, but configurable
type StopListening = IO ()Source
An action that cancels a watching/listening job
isPollingManager :: WatchManager -> BoolSource
Does this manager use polling?
Watching
watchDir :: WatchManager -> FilePath -> ActionPredicate -> Action -> IO StopListeningSource
Watch the immediate contents of a directory by committing an Action for each event. Watching the immediate contents of a directory will only report events associated with files within the specified directory, and not files within its subdirectories. No two events pertaining to the same FilePath will be executed concurrently.
watchDirChan :: WatchManager -> FilePath -> ActionPredicate -> EventChannel -> IO StopListeningSource
Watch the immediate contents of a directory by streaming events to a Chan. Watching the immediate contents of a directory will only report events associated with files within the specified directory, and not files within its subdirectories.
watchTree :: WatchManager -> FilePath -> ActionPredicate -> Action -> IO StopListeningSource
Watch all the contents of a directory by committing an Action for each event. Watching all the contents of a directory will report events associated with files within the specified directory and its subdirectories. No two events pertaining to the same FilePath will be executed concurrently.
watchTreeChan :: WatchManager -> FilePath -> ActionPredicate -> EventChannel -> IO StopListeningSource
Watch all the contents of a directory by streaming events to a Chan. Watching all the contents of a directory will report events associated with files within the specified directory and its subdirectories.