mirror of
https://github.com/go-ping/ping.git
synced 2025-07-16 15:15:55 +00:00
refactor: simplify handling of done channel
This commit is contained in:
parent
dbd1b5c8a8
commit
8ef5fddf90
11
ping.go
11
ping.go
@ -96,7 +96,7 @@ func New(addr string) *Pinger {
|
||||
Size: timeSliceLength + trackerLength,
|
||||
Timeout: time.Duration(math.MaxInt64),
|
||||
addr: addr,
|
||||
done: make(chan interface{}),
|
||||
done: make(chan struct{}),
|
||||
id: r.Intn(math.MaxUint16),
|
||||
currentUUID: uuid.New(),
|
||||
ipaddr: nil,
|
||||
@ -190,7 +190,7 @@ type Pinger struct {
|
||||
Source string
|
||||
|
||||
// Channel and mutex used to communicate when the Pinger should stop between goroutines.
|
||||
done chan interface{}
|
||||
done chan struct{}
|
||||
lock sync.Mutex
|
||||
|
||||
ipaddr *net.IPAddr
|
||||
@ -549,13 +549,10 @@ func (p *Pinger) Stop() {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
|
||||
open := true
|
||||
select {
|
||||
case _, open = <-p.done:
|
||||
case <-p.done:
|
||||
return
|
||||
default:
|
||||
}
|
||||
|
||||
if open {
|
||||
close(p.done)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user