Help improve this documentation
This documentation is still new and evolving. If you spot any mistakes, unclear explanations, or missing details, please open an issue.
Your feedback helps us improve!
FSNotify operatorsโ
This page lists all operators available in the fsnotify
sub-package of ro.
Installโ
First, import the sub-package in your project:
go get -u github.com/samber/ro/plugins/fsnotify
NewFSListenerโ
Creates an observable that monitors file system events for specified paths.
import (
"fmt"
"github.com/fsnotify/fsnotify"
"github.com/samber/ro"
rofsnotify "github.com/samber/ro/plugins/fsnotify"
)
obs := rofsnotify.NewFSListener("/tmp")
sub := obs.Subscribe(ro.NewObserver(
func(event fsnotify.Event) {
switch event.Op {
case fsnotify.Create:
fmt.Println("File was created")
case fsnotify.Write:
fmt.Println("File was written to")
case fsnotify.Remove:
fmt.Println("File was removed")
}
},
func(err error) {
fmt.Printf("Error: %v\n", err)
},
func() {
fmt.Println("Completed")
},
))
defer sub.Unsubscribe()
// When file events occur:
// File was created
// File was written to
// File was removedPrototype:func NewFSListener(paths ...string)