cork

package module
v0.0.0-...-3fd4274 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2021 License: MIT Imports: 9 Imported by: 0

README

cork GoDoc

Package cork is a file event handler.

For a watchman-make alternative, see cork-make.

There's an ablative layer of cork on Minuteman II missiles.

To do

  • Periodic reselection.
  • Action concurrency, bottlenecking.
  • cork-make: CLI man/help.
  • cork-make: clean up logging (split err/out; lock out concurrent cmd output).
  • cork-make: tests.

Documentation

Overview

Package cork is a file event handler.

Example
var normalAction Action = func(e Event, cached string) string {
	log.Println("Normal cache:", cached)
	return "The normal cache never changes."
}

w1, _ := Watch(func() []string {
	return []string{"./testdir"}
}, normalAction.OnFileWrite())
defer w1.Close()

var specialAction Action = func(e Event, cached string) string {
	log.Println("Filechange cache:", cached)
	return ""
}

w2, _ := Watch(func() []string {
	return []string{"./testdir"}
}, specialAction.OnFileChange().OnFileWrite())
defer w2.Close()

// Run indefinitely.
var c chan struct{}
<-c
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action func(e Event, cached string) string

An Action receives an event and the previous cached value for the event file name. It returns the new value to be cached.

func (Action) OnFileChange

func (a Action) OnFileChange() Action

OnFileChange runs A iff the hash of the event file has changed. NOTE: this overrides A's cache values.

func (Action) OnFileWrite

func (a Action) OnFileWrite() Action

OnFileWrite runs A iff the event is a file write event.

func (Action) OnRegexChange

func (a Action) OnRegexChange(regex string) Action

OnRegexChange runs A iff the result of finding all REGEX on the event file is novel. For regex documentation see package `regexp`.

type Event

type Event struct {
	fsnotify.Event
}

An Event proxies an fsnotify.Event.

type Selector

type Selector func() []string

A Selector returns a list of relative file or directory names.

type Watcher

type Watcher struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

A Watcher watches file events and caches Action outputs.

func Watch

func Watch(s Selector, a Action) (*Watcher, error)

Watch creates returns a new Watcher that watches the files returned by S, and applies action A upon events from those files. You must call watcher.Close() to prevent memory leaks to fsnotify watchers.

TODO: rerun selectors to find new files. This can be achieved by feeding timer events to a channel as in `qt`. Store a set of the currently watched files in the watcher.

func (*Watcher) Close

func (w *Watcher) Close()

Close destroys the inner fsnotify watcher to prevent memory leaks.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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