diff options
author | Wolfy-J <[email protected]> | 2019-05-02 22:52:32 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2019-05-02 22:52:32 +0300 |
commit | 62250fde949d2511b1e030c570bafe2ef3ed2c2d (patch) | |
tree | 538a0efeefe7f92e489096850f087b15d6fee8ea /service/watcher/watcher.go | |
parent | e3f8f80b40d55d9d3c2e858a73cc1befe3f04114 (diff) |
symfony way to refernce contributors
Diffstat (limited to 'service/watcher/watcher.go')
-rw-r--r-- | service/watcher/watcher.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/service/watcher/watcher.go b/service/watcher/watcher.go new file mode 100644 index 00000000..9cf129df --- /dev/null +++ b/service/watcher/watcher.go @@ -0,0 +1,50 @@ +package watcher + +import ( + "log" + "time" +) + +// disconnect?? +type Service struct { + // defines how often + interval time.Duration + pool Pool + + stop chan interface{} +} + +// NewWatcher creates new pool watcher. +func NewWatcher(p Pool, i time.Duration) *Service { + w := &Service{ + interval: i, + pool: p, + stop: make(chan interface{}), + } + + go func() { + ticker := time.NewTicker(w.interval) + + for { + select { + case <-ticker.C: + w.update() + case <-w.stop: + return + } + } + }() + + return w +} + +func (w *Service) Stop() { + close(w.stop) +} + +func (w *Service) update() { + for _, w := range w.pool.Workers() { + log.Println(w) + + } +} |