Documentation ¶
Overview ¶
Package watcher provides a simple mechanism to watch a file for changes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher is a structure to watch a file for changes and notify a channel.
func NewWatcher ¶
NewWatcher instantiates a new watcher with the provided filename and changes channel.
func (*Watcher) Run ¶
Run starts the file watcher in a blocking fashion. This watches an entire directory and only notifies the channel when the specified file is changed. If there is an error, it's returned. It's up to the caller to respawn the watcher if it's desireable to keep watching.
The reason it watches a directory is becausde some editers like VIM write to a swap file and recreate the original file. So we can't simply watch the original file, we have to watch the directory. This is also why we check both the WRITE and CREATE events since VIM will write to a swap and then create the file on save. VSCode does a WRITE and then a CHMOD, so tracking WRITE catches the changes for VSCode exactly once.