Replace explicit channels with functions
This commit is contained in:
@@ -12,7 +12,8 @@ import (
|
||||
)
|
||||
|
||||
type Looper interface {
|
||||
Run(ctx context.Context, restart <-chan struct{}, wg *sync.WaitGroup)
|
||||
Run(ctx context.Context, wg *sync.WaitGroup)
|
||||
Restart()
|
||||
}
|
||||
|
||||
type looper struct {
|
||||
@@ -23,6 +24,7 @@ type looper struct {
|
||||
streamMerger command.StreamMerger
|
||||
uid int
|
||||
gid int
|
||||
restart chan struct{}
|
||||
}
|
||||
|
||||
func (l *looper) logAndWait(ctx context.Context, err error) {
|
||||
@@ -43,14 +45,17 @@ func NewLooper(conf Configurator, firewallConf firewall.Configurator, settings s
|
||||
streamMerger: streamMerger,
|
||||
uid: uid,
|
||||
gid: gid,
|
||||
restart: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *looper) Run(ctx context.Context, restart <-chan struct{}, wg *sync.WaitGroup) {
|
||||
func (l *looper) Restart() { l.restart <- struct{}{} }
|
||||
|
||||
func (l *looper) Run(ctx context.Context, wg *sync.WaitGroup) {
|
||||
wg.Add(1)
|
||||
defer wg.Done()
|
||||
select {
|
||||
case <-restart:
|
||||
case <-l.restart:
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
@@ -102,7 +107,7 @@ func (l *looper) Run(ctx context.Context, restart <-chan struct{}, wg *sync.Wait
|
||||
<-waitError
|
||||
close(waitError)
|
||||
return
|
||||
case <-restart: // triggered restart
|
||||
case <-l.restart: // triggered restart
|
||||
l.logger.Info("restarting")
|
||||
tinyproxyCancel()
|
||||
<-waitError
|
||||
|
||||
Reference in New Issue
Block a user