unison-cli-0.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Unison.Codebase.Watch

Synopsis

Documentation

watchPath :: WatchState -> FilePath -> IO (Maybe FilePath) Source #

Add a file or directory to be watched. Returns the canonical path if successful, Nothing otherwise.

Each watched path spawns a background thread via Ki that manages the FSNotify watcher. When the Ki scope exits, all watcher threads are automatically cleaned up.

data WatchState Source #

State for managing multiple watched paths.

Constructors

WatchState 

Fields

newWatchState :: WatchManager -> (FilePath -> Bool) -> IO WatchState Source #

Create a new watch state. The Ki scope is used for structured concurrency - when the scope exits, all watcher threads are automatically cleaned up.

awaitEvent :: WatchState -> IO (FilePath, Text) Source #

Await an event from any watched source.

This function implements debouncing with the following logic, intended to work around the tendency for modern editors to create a flurry of rapid filesystem events when a file is saved:

  1. Block until an event arrives.
  2. Keep consuming events until 50ms elapse without an event.
  3. Return only the last event.

Note we don't have any smarts here for a flurry of events that are related to more than one file; we just throw everything away except the last event. In practice, this has seemed to work fine.

Additionally, we keep in memory the file contents of previously-saved files, so that we can avoid emitting events for files that last changed less than 500ms ago, and whose contents haven't changed.

unwatchPath :: WatchState -> FilePath -> IO Bool Source #

Stop watching a path. Returns True if the path was being watched.

getWatchedPaths :: WatchState -> IO (Set FilePath) Source #

Get the list of currently watched paths.