fsnotify

package module
v0.0.0-...-285fe68 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2022 License: MIT Imports: 6 Imported by: 0

README

fsnotify

Currently, this is a study in how I would go about implementing a fsnotify implementation, where the backend drivers can be pluggable.

The design differs significantly from https://github.com/fsnotify/fsnotify, in that this package:

  1. Uses contet.Context
  2. Allows user to choose where to send their data via use of abstract Sinks
  3. Does not implicitly use goroutines, but rather asks the user to choose by providing a w.Watch() method that can be called as go w.Watch(...)

CURRENT STATUS

THIS PACKAGE DOES NOT WORK YET. IT'S A CONCEPT/STUDY.

  • Wrote preliminary API design for fsnotify
  • Seeing how I would write fsnotify-inotify backend
    • decided to bundle it in a different package withing this repository
    • SOMETHING works. Not entirely tested

SYNOPSIS


import (
  "context"
  "os/signal"
  "syscall"

  "github.com/lestrrat-go/fsnotify"
)

func main() {
  ctx, cancel := signal.NotifyContext(
    context.Background(),
    syscall.SIGHUP,
    syscall.SIGTERM,
    syscall.SIGQUIT,
  )
  defer cancel()


  w := fsnotify.New()
  w.Add(`/path/fo/target`)

  evCh := make(chan *fsnotify.Event)
  errCh := make(chan error)
  go w.Watch(ctx, 
    fsnotify.WithEventSink(fsnotify.ChannelEventSink(evCh)),
    fsnotify.WithErrorSink(fsnotify.ChannelErrorSink(errCh)),
  )

  for {
    select {
    case <-ctx.Done():
      return
    case ev := <-evCh:
      ...
    case err := <-errCh:
      ...
    }
  }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChannelErrorSink

type ChannelErrorSink chan error

func (ChannelErrorSink) Error

func (sink ChannelErrorSink) Error(err error)

type ChannelEventSink

type ChannelEventSink chan api.Event

func (ChannelEventSink) Event

func (sink ChannelEventSink) Event(ev api.Event)

type CommandOption

type CommandOption = api.CommandOption

type Option

type Option = option.Interface

type WatchOption

type WatchOption interface {
	Option
	// contains filtered or unexported methods
}

func WithErrorSink

func WithErrorSink(sink api.ErrorSink) WatchOption

func WithEventSink

func WithEventSink(sink api.EventSink) WatchOption

type Watcher

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

func Create

func Create(d api.Driver) *Watcher

Create creates a new Watcher using the specified Driver.

func New

func New() *Watcher

func (*Watcher) Add

func (w *Watcher) Add(fn string)

func (*Watcher) Driver

func (w *Watcher) Driver() api.Driver

func (*Watcher) Remove

func (w *Watcher) Remove(fn string)

func (*Watcher) Watch

func (w *Watcher) Watch(ctx context.Context, options ...WatchOption)

Watch starts the watcher. By default it watches in the foreground, therefore if you would like this to run in the background you should execute it as a separate goroutine.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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