chikador

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Recursive = func(options *options) {
	options.recursive = true
}

Recursive will make chikador scan through the directory and its subdirectories to add to the file watcher.

View Source
var WithDedupe = func(options *options) {
	options.kind = withDedupe
}

WithDedupe enables deduping of events. As operating systems tends to duplicate events around and give you "unnecessary noise", for most cases, it is recommended to enable this unless you need those "unnecessary noise".

View Source
var WithoutDedupe = func(options *options) {
	options.kind = withoutDedupe
}

WithoutDedupe explicitly states that the Chismis instance shouldn't dedupe events, this is the default behavior, and this is only added for completeness and when you want to explicitly indicate the behavior.

Functions

This section is empty.

Types

type Chismis

type Chismis struct {
	// contains filtered or unexported fields
}

func Watch

func Watch(path string, opts ...Option) (*Chismis, error)

Watch creates a new Chismis instance that is watching over the given path, and its subdirectories if Recursive is enabled. You can add the following options to give more power to the file watching capabilities:

* Recursive: adds all the subdirectories under the directory and the subdirectories' subdirectories' subdirectories' sub.... you get it.

* WithDedupe: (recommended) dedupes events which operating systems tend to have, this uses the implementation from fsnotify's own repository.

func (*Chismis) Close

func (chismis *Chismis) Close() error

Close removes all watches and closes all event channels.

func (*Chismis) IsClosed

func (chismis *Chismis) IsClosed() bool

IsClosed checks whether this Chismis channel is already closed, important if you want to stop program immediately when closed.

func (*Chismis) Listen

func (chismis *Chismis) Listen(fn func(msg *Message))

Listen listens to events from the event queue, this is running in another goroutine and uses the same polling method internally.

Do note that you shouldn't listen to a Chismis instance twice, only one listener ever, not even Poll, as this will result in the resource being contended.

func (*Chismis) Poll

func (chismis *Chismis) Poll() *Message

Poll tries to poll data from the event queue, if there is none then it will return a nil pointer. Recommended to use in a forever for-loop to continuously poll data. Alternatively, you can use Listen which is the same as a for-loop, but asynchronous and shorter.

Do note that you shouldn't have this twice, nor should you also use Listen if you are already polling data with this method as the two methods will battle it out over who has the resource.

type Message

type Message struct {
	Event    fsnotify.Op
	Filename string
	Error    error
}

type Option

type Option func(options *options)

Jump to

Keyboard shortcuts

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