watcher

package
v0.22.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

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

func NewWatcher(filename string, fileChanges chan bool) *Watcher

NewWatcher instantiates a new watcher with the provided filename and changes channel.

func (*Watcher) Run

func (w *Watcher) Run() error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL