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 ¶
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 ¶
OnFileChange runs A iff the hash of the event file has changed. NOTE: this overrides A's cache values.
func (Action) OnFileWrite ¶
OnFileWrite runs A iff the event is a file write event.
func (Action) OnRegexChange ¶
OnRegexChange runs A iff the result of finding all REGEX on the event file is novel. For regex documentation see package `regexp`.
type Selector ¶
type Selector func() []string
A Selector returns a list of relative file or directory names.
type Watcher ¶
A Watcher watches file events and caches Action outputs.
func Watch ¶
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.