Refactor network monitor to wait for stop (#1992)

This commit is contained in:
Viktor Liu
2024-05-17 09:43:18 +02:00
committed by GitHub
parent a5811a2d7d
commit bd58eea8ea
7 changed files with 74 additions and 52 deletions

View File

@@ -2,14 +2,20 @@ package networkmonitor
import (
"context"
"errors"
"sync"
)
// NetworkWatcher watches for changes in network configuration.
type NetworkWatcher struct {
var ErrStopped = errors.New("monitor has been stopped")
// NetworkMonitor watches for changes in network configuration.
type NetworkMonitor struct {
cancel context.CancelFunc
wg sync.WaitGroup
mu sync.Mutex
}
// New creates a new network monitor.
func New() *NetworkWatcher {
return &NetworkWatcher{}
func New() *NetworkMonitor {
return &NetworkMonitor{}
}