本文整理汇总了Golang中github.com/rjeczalik/notify.Stop函数的典型用法代码示例。如果您正苦于以下问题:Golang Stop函数的具体用法?Golang Stop怎么用?Golang Stop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Stop函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ExampleWatch_darwinCoalesce
// FSEvents may report multiple filesystem actions with one, coalesced event.
// Notify unscoalesces such event and dispatches series of single events
// back to the user.
//
// This example shows how to coalesce events by investigating notify.(*FSEvent).ID
// field, for the science.
func ExampleWatch_darwinCoalesce() {
// Make the channels buffered to ensure no event is dropped. Notify will drop
// an event if the receiver is not able to keep up the sending pace.
c := make(chan notify.EventInfo, 4)
// Set up a watchpoint listetning for events within current working directory.
// Dispatch all platform-independent separately to c.
if err := notify.Watch(".", c, notify.All); err != nil {
log.Fatal(err)
}
defer notify.Stop(c)
var id uint64
var coalesced []notify.EventInfo
for ei := range c {
switch n := ei.Sys().(*notify.FSEvent).ID; {
case id == 0:
id = n
coalesced = []notify.EventInfo{ei}
case id == n:
coalesced = append(coalesced, ei)
default:
log.Printf("FSEvents reported a filesystem action with the following"+
" coalesced events %v groupped by %d ID\n", coalesced, id)
return
}
}
}
开发者ID:kaocs,项目名称:notify,代码行数:35,代码来源:example_fsevents_test.go
示例2: setUpFolderListener
func setUpFolderListener(path string, stop <-chan bool) {
os.RemoveAll(path)
os.Mkdir(path, os.ModePerm)
replacer := replacer.NewMakerRegistry(path)
for _, format := range allFormats() {
for _, class := range allClasses() {
replacer.Add(format, class)
}
}
c := make(chan notify.EventInfo, 1000)
if err := notify.Watch(path, c, notify.Rename, notify.Remove); err != nil {
log.Fatal(err)
}
defer notify.Stop(c)
go func() {
for {
select {
case event := <-c:
replacer.Replace(event.Path())
}
}
}()
<-stop
}
开发者ID:neil-ca-moore,项目名称:language-tool,代码行数:28,代码来源:main.go
示例3: ExampleStop
// This example shows why it is important to not create leaks by stoping
// a channel when it's no longer being used.
func ExampleStop() {
waitfor := func(path string, e notify.Event, timeout time.Duration) bool {
dir, file := filepath.Split(path)
c := make(chan notify.EventInfo, 1)
if err := notify.Watch(dir, c, e); err != nil {
log.Fatal(err)
}
// Clean up watchpoint associated with c. If Stop was not called upon
// return the channel would be leaked as notify holds the only reference
// to it and does not release it on its own.
defer notify.Stop(c)
t := time.After(timeout)
for {
select {
case ei := <-c:
if filepath.Base(ei.Path()) == file {
return true
}
case <-t:
return false
}
}
}
if waitfor("index.lock", notify.Create, 5*time.Second) {
log.Println("The git repository was locked")
}
if waitfor("index.lock", notify.Remove, 5*time.Second) {
log.Println("The git repository was unlocked")
}
}
开发者ID:kaocs,项目名称:notify,代码行数:37,代码来源:example_test.go
示例4: main
func main() {
// Make the channel buffered to ensure no event is dropped. Notify will drop
// an event if the receiver is not able to keep up the sending pace.
c := make(chan notify.EventInfo, 1)
// Set up a watchpoint listening for inotify-specific events within a
// current working directory. Dispatch each InCloseWrite and InMovedTo
// events separately to c.
if err := notify.Watch(".", c, notify.FSEventsModified, notify.FSEventsRemoved); err != nil {
log.Fatal(err)
}
defer notify.Stop(c)
// Block until an event is received.
switch ei := <-c; ei.Event() {
case notify.FSEventsChangeOwner:
log.Println("The owner of", ei.Path(), "has changed.")
case notify.FSEventsMount:
log.Println("The path", ei.Path(), "has been mounted.")
}
// switch ei := <-c; ei.Event() {
// case notify.FSEventsModified:
// log.Println("Editing of", ei.Path(), "file is done.")
// case notify.FSEventsRemoved:
// log.Println("File", ei.Path(), "was swapped/moved into the watched directory.")
// }
}
开发者ID:zchee,项目名称:go-sandbox,代码行数:27,代码来源:watch_fsevents.go
示例5: ExampleWatch_windows
// This example shows how to watch directory-name changes in the working directory subtree.
func ExampleWatch_windows() {
// Make the channel buffered to ensure no event is dropped. Notify will drop
// an event if the receiver is not able to keep up the sending pace.
c := make(chan notify.EventInfo, 4)
// Since notify package behaves exactly like ReadDirectoryChangesW function,
// we must register notify.FileNotifyChangeDirName filter and wait for one
// of FileAction* events.
if err := notify.Watch("./...", c, notify.FileNotifyChangeDirName); err != nil {
log.Fatal(err)
}
defer notify.Stop(c)
// Wait for actions.
for ei := range c {
switch ei.Event() {
case notify.FileActionAdded, notify.FileActionRenamedNewName:
log.Println("Created:", ei.Path())
case notify.FileActionRemoved, notify.FileActionRenamedOldName:
log.Println("Removed:", ei.Path())
case notify.FileActionModified:
panic("notify: unexpected action")
}
}
}
开发者ID:kaocs,项目名称:notify,代码行数:26,代码来源:example_readdcw_test.go
示例6: loop
func (w *watcher) loop() {
defer func() {
w.ac.mu.Lock()
w.running = false
w.starting = false
w.ac.mu.Unlock()
}()
err := notify.Watch(w.ac.keydir, w.ev, notify.All)
if err != nil {
glog.V(logger.Detail).Infof("can't watch %s: %v", w.ac.keydir, err)
return
}
defer notify.Stop(w.ev)
glog.V(logger.Detail).Infof("now watching %s", w.ac.keydir)
defer glog.V(logger.Detail).Infof("no longer watching %s", w.ac.keydir)
w.ac.mu.Lock()
w.running = true
w.ac.mu.Unlock()
// Wait for file system events and reload.
// When an event occurs, the reload call is delayed a bit so that
// multiple events arriving quickly only cause a single reload.
var (
debounce = time.NewTimer(0)
debounceDuration = 500 * time.Millisecond
inCycle, hadEvent bool
)
defer debounce.Stop()
for {
select {
case <-w.quit:
return
case <-w.ev:
if !inCycle {
debounce.Reset(debounceDuration)
inCycle = true
} else {
hadEvent = true
}
case <-debounce.C:
w.ac.mu.Lock()
w.ac.reload()
w.ac.mu.Unlock()
if hadEvent {
debounce.Reset(debounceDuration)
inCycle, hadEvent = true, false
} else {
inCycle, hadEvent = false, false
}
}
}
}
开发者ID:expanse-project,项目名称:go-expanse,代码行数:54,代码来源:watch.go
示例7: ExampleWatch_darwinDirFileSymlink
// This example shows how to work with EventInfo's underlying FSEvent struct.
// Investigating notify.(*FSEvent).Flags field we are able to say whether
// the event's path is a file or a directory and many more.
func ExampleWatch_darwinDirFileSymlink() {
var must = func(err error) {
if err != nil {
log.Fatal(err)
}
}
var stop = func(c ...chan<- notify.EventInfo) {
for _, c := range c {
notify.Stop(c)
}
}
// Make the channels buffered to ensure no event is dropped. Notify will drop
// an event if the receiver is not able to keep up the sending pace.
dir := make(chan notify.EventInfo, 1)
file := make(chan notify.EventInfo, 1)
symlink := make(chan notify.EventInfo, 1)
all := make(chan notify.EventInfo, 1)
// Set up a single watchpoint listening for FSEvents-specific events on
// multiple user-provided channels.
must(notify.Watch(".", dir, notify.FSEventsIsDir))
must(notify.Watch(".", file, notify.FSEventsIsFile))
must(notify.Watch(".", symlink, notify.FSEventsIsSymlink))
must(notify.Watch(".", all, notify.All))
defer stop(dir, file, symlink, all)
// Block until an event is received.
select {
case ei := <-dir:
log.Println("The directory", ei.Path(), "has changed")
case ei := <-file:
log.Println("The file", ei.Path(), "has changed")
case ei := <-symlink:
log.Println("The symlink", ei.Path(), "has changed")
case ei := <-all:
var kind string
// Investigate underlying *notify.FSEvent struct to access more
// information about the event.
switch flags := ei.Sys().(*notify.FSEvent).Flags; {
case flags¬ify.FSEventsIsFile != 0:
kind = "file"
case flags¬ify.FSEventsIsDir != 0:
kind = "dir"
case flags¬ify.FSEventsIsSymlink != 0:
kind = "symlink"
}
log.Printf("The %s under path %s has been %sd\n", kind, ei.Path(), ei.Event())
}
}
开发者ID:kaocs,项目名称:notify,代码行数:55,代码来源:example_fsevents_test.go
示例8: notifyLoop
func (m *Manager) notifyLoop() {
defer notify.Stop(m.eventsChan)
for {
select {
case ev := <-m.eventsChan:
m.fileChanged(ev.Path())
case <-m.stopChan:
return
}
}
}
开发者ID:hlandau,项目名称:degoutils,代码行数:13,代码来源:assetmgr.go
示例9: watchFile
func watchFile() {
c := make(chan notify.EventInfo, 1)
if err := notify.Watch("./users.txt", c, 0x04000); err != nil {
fmt.Println("error watching users file", err)
}
defer notify.Stop(c)
// Block until an event is received.
ei := <-c
fmt.Println("Users - watchFile - users file has been changed", ei.Event())
parseAndSetUsers()
go watchFile()
}
开发者ID:LicaSterian,项目名称:unsub,代码行数:13,代码来源:Users.go
示例10: reload
func (d *Dispatcher) reload() {
for {
s := <-d.signal
d.log.Infof("Received %s, reloading configuration", s)
cfg, err := ReadConfig(d.Config.filename)
if err == nil {
d.log.Info("Removing all watches")
notify.Stop(d.watcher)
d.Config = cfg
d.watch()
} else {
d.log.WithError(err).Errorf("Failed to read config")
}
}
}
开发者ID:martinp,项目名称:gounpack,代码行数:15,代码来源:dispatcher.go
示例11: handleOsSignal
func handleOsSignal(watch chan notify.EventInfo) {
osSignal := make(chan os.Signal, 1)
signal.Notify(osSignal, os.Interrupt)
go func() {
for {
signalNumber := <-osSignal
if signalNumber == syscall.SIGINT || signalNumber == syscall.SIGKILL {
notify.Stop(watch)
os.Exit(1)
}
}
}()
}
开发者ID:unbalancedparentheses,项目名称:stalk,代码行数:15,代码来源:main.go
示例12: main
func main() {
// Make the channel buffered to ensure no event is dropped. Notify will drop
// an event if the receiver is not able to keep up the sending pace.
c := make(chan notify.EventInfo, 1)
// Set up a watchpoint listening on events within current working directory.
// Dispatch each create and remove events separately to c.
if err := notify.Watch(".", c, notify.Create, notify.Remove); err != nil {
log.Fatal(err)
}
defer notify.Stop(c)
// Block until an event is received.
ei := <-c
log.Println("Got event:", ei)
}
开发者ID:zchee,项目名称:go-sandbox,代码行数:16,代码来源:eventwatch.go
示例13: ExampleWatch_recursive
// This example shows how to set up a recursive watchpoint.
func ExampleWatch_recursive() {
// Make the channel buffered to ensure no event is dropped. Notify will drop
// an event if the receiver is not able to keep up the sending pace.
c := make(chan notify.EventInfo, 1)
// Set up a watchpoint listening for events within a directory tree rooted
// at current working directory. Dispatch remove events to c.
if err := notify.Watch("./...", c, notify.Remove); err != nil {
log.Fatal(err)
}
defer notify.Stop(c)
// Block until an event is received.
ei := <-c
log.Println("Got event:", ei)
}
开发者ID:kaocs,项目名称:notify,代码行数:17,代码来源:example_test.go
示例14: main
func main() {
repotmp := "/repo/PKGBUILD/"
currentuser, _ := user.Current()
homedirs, _ := getHomes("/home/*")
logFile := StartLog("/var/log/pkgbuild.log", currentuser)
defer logFile.Close()
Info.Println("\n\n\t\tI don't know who you are\n\t\tI don't know what you are syncing\n\t\tIf you are syncing via rsync, I can tell you \n\t\tI don't have the condition to pick it\n\t\tBut what I do have are a very particular set of channels\n\t\tChannels that pick up debs and push it to the repo\n\t\tI will look for debs in", homedirs, ", \n\t\tI will find it, and I will add it to repo . . .\n")
fmt.Println("\n\n\t\tI don't know who you are\n\t\tI don't know what you are syncing\n\t\tIf you are syncing via rsync, I can tell you \n\t\tI don't have the condition to pick it\n\t\tBut what I do have are a very particular set of channels\n\t\tChannels that pick up debs and push it to the repo\n\t\tI will look for debs in", homedirs, ", \n\t\tI will find it, and I will add it to repo . . .\n")
Info.Println("Starting taken . . .\nUse scp to copy deb files.")
fmt.Println("Starting taken . . .\nUse scp to copy deb files.")
Info.Println("Deb files will be moved to ", repotmp, "before pushing to repo")
c := make(chan notify.EventInfo, 20)
for _, i := range homedirs {
if err := notify.Watch(i, c, notify.InCloseWrite, notify.Create); err != nil {
log.Fatal(err)
}
}
/*if err := notify.Watch("/home/girishg/", c, notify.InCloseWrite, notify.All); err != nil {
log.Fatal(err)
}
if err := notify.Watch("/home/anotheruser/", c, notify.InCloseWrite, notify.All); err != nil {
log.Fatal(err)
}*/
defer notify.Stop(c)
for ei := range c {
switch ei.Event() {
case notify.Create:
Info.Println(ei.Event(), ei.Path())
case notify.InCloseWrite:
Info.Println(ei.Event(), ei.Path())
if ValidateDeb(ei.Path()) {
debfile := moveDebs(ei.Path(), repotmp)
CallAptlyAdd(debfile)
CallAptlyShow()
CallAptlyPublish()
}
}
}
}
开发者ID:nohupped,项目名称:taken,代码行数:47,代码来源:taken.go
示例15: Unmonitor
// Unmonitor the given path.
func (f *FileMonitor) Unmonitor(id string, globs []*glob.Glob) {
for _, g := range globs {
entries, ok := f.monitors[g.Dir()]
if !ok {
continue
}
entry, ok := entries[id]
if !ok {
continue
}
entry.globs.Remove(g)
if len(entry.globs) == 0 {
notify.Stop(entry.ch)
close(entry.ch)
delete(entries, id)
}
}
}
开发者ID:alecthomas,项目名称:buildkit,代码行数:19,代码来源:monitor.go
示例16: ExampleWatch_linuxMove
// This example shows how to use Sys() method from EventInfo interface to tie
// two separate events generated by rename(2) function.
func ExampleWatch_linuxMove() {
// Make the channel buffered to ensure no event is dropped. Notify will drop
// an event if the receiver is not able to keep up the sending pace.
c := make(chan notify.EventInfo, 2)
// Set up a watchpoint listening for inotify-specific events within a
// current working directory. Dispatch each InMovedFrom and InMovedTo
// events separately to c.
if err := notify.Watch(".", c, notify.InMovedFrom, notify.InMovedTo); err != nil {
log.Fatal(err)
}
defer notify.Stop(c)
// Inotify reports move filesystem action by sending two events tied with
// unique cookie value (uint32): one of the events is of InMovedFrom type
// carrying move source path, while the second one is of InMoveTo type
// carrying move destination path.
moves := make(map[uint32]struct {
From string
To string
})
// Wait for moves.
for ei := range c {
cookie := ei.Sys().(*syscall.InotifyEvent).Cookie
info := moves[cookie]
switch ei.Event() {
case notify.InMovedFrom:
info.From = ei.Path()
case notify.InMovedTo:
info.To = ei.Path()
}
moves[cookie] = info
if cookie != 0 && info.From != "" && info.To != "" {
log.Println("File:", info.From, "was renamed to", info.To)
delete(moves, cookie)
}
}
}
开发者ID:kaocs,项目名称:notify,代码行数:43,代码来源:example_inotify_test.go
示例17: ExampleWatch_darwin
// This example shows how to use FSEvents-specifc event values.
func ExampleWatch_darwin() {
// Make the channel buffered to ensure no event is dropped. Notify will drop
// an event if the receiver is not able to keep up the sending pace.
c := make(chan notify.EventInfo, 1)
// Set up a watchpoint listening for FSEvents-specific events within a
// current working directory. Dispatch each FSEventsChangeOwner and FSEventsMount
// events separately to c.
if err := notify.Watch(".", c, notify.FSEventsChangeOwner, notify.FSEventsMount); err != nil {
log.Fatal(err)
}
defer notify.Stop(c)
// Block until an event is received.
switch ei := <-c; ei.Event() {
case notify.FSEventsChangeOwner:
log.Println("The owner of", ei.Path(), "has changed.")
case notify.FSEventsMount:
log.Println("The path", ei.Path(), "has been mounted.")
}
}
开发者ID:kaocs,项目名称:notify,代码行数:22,代码来源:example_fsevents_test.go
示例18: ExampleWatch_linux
// This example shows how to watch changes made on file-system by text editor
// when saving a file. Usually, either InCloseWrite or InMovedTo (when swapping
// with a temporary file) event is created.
func ExampleWatch_linux() {
// Make the channel buffered to ensure no event is dropped. Notify will drop
// an event if the receiver is not able to keep up the sending pace.
c := make(chan notify.EventInfo, 1)
// Set up a watchpoint listening for inotify-specific events within a
// current working directory. Dispatch each InCloseWrite and InMovedTo
// events separately to c.
if err := notify.Watch(".", c, notify.InCloseWrite, notify.InMovedTo); err != nil {
log.Fatal(err)
}
defer notify.Stop(c)
// Block until an event is received.
switch ei := <-c; ei.Event() {
case notify.InCloseWrite:
log.Println("Editing of", ei.Path(), "file is done.")
case notify.InMovedTo:
log.Println("File", ei.Path(), "was swapped/moved into the watched directory.")
}
}
开发者ID:kaocs,项目名称:notify,代码行数:24,代码来源:example_inotify_test.go
示例19: fileMon
/*
Monitoring changes in file system.
It designed for run in separate goroutine.
*/
func fileMon(path string, bus chan fileChangeEvent) {
// Make the channel buffered to ensure no event is dropped. Notify will drop
// an event if the receiver is not able to keep up the sending pace.
c := make(chan notify.EventInfo, 1)
// Set up a watchpoint listening on events within current working directory.
// Dispatch each create and remove events separately to c.
if err := notify.Watch(path+"/...", c, notify.All); err != nil {
log.Fatal(err)
}
defer notify.Stop(c)
// Block until an event is received.
for {
event := <-c
fstat, err := os.Lstat(event.Path())
if os.IsNotExist(err) {
bus <- fileChangeEvent{Path: event.Path(), IsRemoved: true}
continue
}
if err != nil {
log.Println(err)
continue
}
if fstat.IsDir() {
bus <- fileChangeEvent{Path: event.Path(), IsDir: true}
continue
}
content, err := ioutil.ReadFile(event.Path())
if err != nil {
log.Println(err)
}
bus <- fileChangeEvent{Path: event.Path(), Content: content}
}
}
开发者ID:fanyang1988,项目名称:etcddir,代码行数:42,代码来源:main.go
示例20: Watch
// Watch watches a set of paths. Mod structs representing a changeset are sent
// on the channel ch.
//
// Watch applies heuristics to cope with transient files and unreliable event
// notifications. Modifications are batched up until there is a a lull in the
// stream of changes of duration lullTime. This lets us represent processes
// that progressively affect multiple files, like rendering, as a single
// changeset.
//
// All paths emitted are slash-delimited.
func Watch(paths []string, lullTime time.Duration, ch chan *Mod) (*Watcher, error) {
evtch := make(chan notify.EventInfo, 4096)
for _, p := range paths {
err := notify.Watch(p, evtch, notify.All)
if err != nil {
notify.Stop(evtch)
return nil, err
}
}
go func() {
for {
b := batch(lullTime, MaxLullWait, statExistenceChecker{}, evtch)
if b != nil && !b.Empty() {
ret, err := b.normPaths(paths)
if err != nil {
Logger.Shout("Error normalising paths: %s", err)
}
ch <- ret
}
}
}()
return &Watcher{evtch}, nil
}
开发者ID:shaunstanislaus,项目名称:modd,代码行数:33,代码来源:watch.go
注:本文中的github.com/rjeczalik/notify.Stop函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论