Esempio n. 1
0
func (this *watcher) Watch(path string, done <-chan bool) (<-chan IFSEvent, error) {
	if err := this.doAdd(path, IN_ALL_EVENTS); err != nil {
		return nil, err
	}

	events := make(chan IFSEvent)
	go func() {
		defer close(events)
		devNull := make(chan error)
		go func() {
			for err := range devNull {
				log.Printf("/dev/null/errors: %s\n", err.Error())
			}
		}()

		this.doReadEvents(IN_ALL_EVENTS, events, devNull, done)

		this.doDel(path)

		errno := syscall.Close(this.kq)
		if errno != nil {
			devNull <- os.NewSyscallError("close", errno)
		}
	}()

	return events, nil
}
Esempio n. 2
0
func (this *watcher) Watch(path string, done <-chan bool) (<-chan IFSEvent, error) {
	if err := this.doAdd(path, IN_ALL_EVENTS); err != nil {
		return nil, err
	}

	events := make(chan IFSEvent)
	go func() {
		defer close(events)
		devNull := make(chan error)

		wg := sync.WaitGroup{}
		wg.Add(1)
		go func() {
			defer wg.Done()
			for err := range devNull {
				log.Printf("/dev/null/errors: %s\n", err.Error())
			}
		}()

		wg.Add(1)
		go func() {
			defer func() {
				close(devNull)
				wg.Done()
			}()

			this.doReadEvents(IN_ALL_EVENTS, events, devNull, done)
		}()

		wg.Add(1)
		go func() {
			defer wg.Done()

			<-done
			this.doDel()

			errno := syscall.Close(this.fd)
			if errno != nil {
				devNull <- os.NewSyscallError("close", errno)
			}
		}()
		wg.Wait()
	}()

	return events, nil
}