Close channel once.

This commit is contained in:
Arijit Das
2020-06-01 15:18:13 +05:30
parent 803257c710
commit 21e0a2f8c2
+8 -3
View File
@@ -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)
})
}
}