observer

package
v0.0.0-...-640b591 Latest Latest
Warning

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

Go to latest
Published: May 22, 2018 License: Apache-2.0 Imports: 8 Imported by: 5

Documentation

Overview

Package observer implements an event emitter and listener with builtin file watcher.

Package observer implements an event emitter and listener with builtin file watcher.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Listener

type Listener func(interface{})

Listener is the function type to run on events.

type Observer

type Observer struct {
	Verbose bool
	// contains filtered or unexported fields
}

Observer emplements the observer pattern.

func (*Observer) AddListener

func (o *Observer) AddListener(l Listener)

AddListener adds a listener function to run on event, the listener function will recive the event object as argument.

func (*Observer) Close

func (o *Observer) Close() error

Close the observer channles, it will return an error if close fails.

func (*Observer) Emit

func (o *Observer) Emit(event interface{})

Emit an event, and event can be of any type, when event is triggered all listeners will be called using the event object.

func (*Observer) Open

func (o *Observer) Open() error

Open the observer channles and run the event loop, it will return an error if event loop already running.

func (*Observer) SetBufferDuration

func (o *Observer) SetBufferDuration(d time.Duration)

SetBufferDuration set the event buffer damping duration.

func (*Observer) Watch

func (o *Observer) Watch(files []string) error

Watch for file changes, watching a file can be done using exact file name, or shell pattern matching.

type Op

type Op uint32

Op (fsnotify.Op) describes a set of file operations.

const (
	Create Op = 1 << iota
	Write
	Remove
	Rename
	Chmod
)

These are the generalized file operations that can trigger a notification.

func (Op) String

func (op Op) String() string

String (fsnotify.Op.String)

type WatchEvent

type WatchEvent struct {
	Name string // Relative path to the file or directory.
	Op   Op     // File operation that triggered the event.
}

WatchEvent (fsnotify.Event) represents a single file system notification.

Directories

Path Synopsis
Package set for unique collection of strings.
Package set for unique collection of strings.

Jump to

Keyboard shortcuts

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