watch

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package watch implements file watching utilities.

1. This is not concerned with very large directories. 2. The focus is on simplicity for use in build tools. 3. Cross platform support would be abstracted into a singe API. 4. Context-aware Streams-based API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close(s Stream) error

Close closes a stream by checking if the stream implements io.Closer.

func Glob

func Glob(pattern string) (allow func(path string) bool)

Glob tests if strings match the specified pattern.

func LastModifiedChecksum

func LastModifiedChecksum(path string) interface{}

LastModifiedChecksum uses the last modified time as the checksum for a path.

Types

type Stream

type Stream interface {
	NextPath(ctx context.Context) (string, error)
}

Stream is the main interface implemented by various watchers.

It is the basis for composition (such as with Delay or Repeat or Filter).

func CurrentDir

func CurrentDir(glob string) Stream

CurrentDir automatically picks the current dir but also filters by the glob pattern.

func Dedup

func Dedup(checksum func(string) interface{}, s Stream) Stream

Dedup drops duplicates in the stream.

Duplicates are identified by comparing the results of the checksum against previous results, if any.

If the checksum returns nil, the last checksum is uncached.

func Delay

func Delay(duration time.Duration, s Stream) Stream

Delay waits for the specified time before allowing the first call to proceed. This is useful when combined with Repeat to setup a polling interval.

func Dir

func Dir(dir string) Stream

Dir returns a snapshot + all changes

func DirSnap

func DirSnap(root string) Stream

DirSnap snapshots a dir and returns all the current files via the Stream. It does not watch for changes after that, returning an io.EOF instead. NextPath must not be called after an EOF is returned.

func Error

func Error(err error) Stream

Error implements a stream that always returns errors.

func Filter

func Filter(allow func(path string) bool, s Stream) Stream

Filter only returns paths matching the allow filter.

func Repeat

func Repeat(create func() Stream) Stream

Repeat calls the create function repeated, iterating through each one until an io.EOF is returned.

Jump to

Keyboard shortcuts

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