mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-05 16:15:56 +00:00
37 lines
685 B
Go
37 lines
685 B
Go
package core
|
|
|
|
import (
|
|
"sync"
|
|
)
|
|
|
|
type Stopper struct {
|
|
TermChans []chan int
|
|
DoneChans []chan int
|
|
Mutex sync.RWMutex
|
|
}
|
|
|
|
func (stopper *Stopper) Stop() {
|
|
var i chan int
|
|
var o chan int
|
|
stopper.Mutex.RLock()
|
|
for _, i = range stopper.TermChans {
|
|
go func() {
|
|
i <- 1
|
|
}()
|
|
}
|
|
for _, o = range stopper.DoneChans {
|
|
<-o
|
|
}
|
|
stopper.Mutex.RUnlock()
|
|
return
|
|
}
|
|
|
|
func (stopper *Stopper) GetExitChannels() (chan int, chan int) {
|
|
termchan := make(chan int, 1)
|
|
donechan := make(chan int, 1)
|
|
stopper.Mutex.Lock()
|
|
stopper.TermChans = append(stopper.TermChans, termchan)
|
|
stopper.DoneChans = append(stopper.DoneChans, donechan)
|
|
stopper.Mutex.Unlock()
|
|
return termchan, donechan
|
|
}
|