mirror of
https://github.com/buger/goreplay.git
synced 2024-04-21 12:32:02 +00:00
Close channel once.
This commit is contained in:
+8
-3
@@ -9,6 +9,7 @@ import (
|
||||
)
|
||||
|
||||
var wg sync.WaitGroup
|
||||
var closeOnce sync.Once
|
||||
|
||||
// Start initialize loop for sending data from inputs to outputs
|
||||
func Start(plugins *InOutPlugins, stop chan int) {
|
||||
@@ -51,8 +52,10 @@ func Start(plugins *InOutPlugins, stop chan int) {
|
||||
}
|
||||
}
|
||||
|
||||
func Close(quit chan int) {
|
||||
close(quit)
|
||||
func Close(quit chan int) {
|
||||
closeOnce.Do(func() {
|
||||
close(quit)
|
||||
})
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
@@ -182,6 +185,8 @@ func CopyMulty(stop chan int, src io.Reader, writers ...io.Writer) {
|
||||
}
|
||||
}
|
||||
if er != nil {
|
||||
close(stop)
|
||||
closeOnce.Do(func() {
|
||||
close(stop)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user