]> Cypherpunks.ru repositories - nncp.git/blob - src/dirwatch_dummy.go
fsnotify usage
[nncp.git] / src / dirwatch_dummy.go
1 // +build nofsnotify
2
3 /*
4 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
5 Copyright (C) 2016-2021 Sergey Matveev <stargrave@stargrave.org>
6
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, version 3 of the License.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 package nncp
21
22 import (
23         "time"
24 )
25
26 type DirWatcher struct {
27         C      chan struct{}
28         ticker *time.Ticker
29 }
30
31 func (ctx *Ctx) NewDirWatcher(dir string, d time.Duration) (*DirWatcher, error) {
32         dw := DirWatcher{C: make(chan struct{}), ticker: time.NewTicker(d)}
33         go func() {
34                 for range dw.ticker.C {
35                         dw.C <- struct{}{}
36                 }
37         }()
38         return &dw, nil
39 }
40
41 func (dw *DirWatcher) Close() {
42         dw.ticker.Stop()
43         for range dw.C {
44         }
45 }