mirror of
https://github.com/netsampler/goflow2.git
synced 2024-05-06 15:54:52 +00:00
29 lines
513 B
Go
29 lines
513 B
Go
package utils
|
|
|
|
import (
|
|
"errors"
|
|
)
|
|
|
|
// ErrAlreadyStarted error happens when you try to start twice a flow routine
|
|
var ErrAlreadyStarted = errors.New("the routine is already started")
|
|
|
|
// stopper mechanism, common for all the flow routines
|
|
type stopper struct {
|
|
stopCh chan struct{}
|
|
}
|
|
|
|
func (s *stopper) start() error {
|
|
if s.stopCh != nil {
|
|
return ErrAlreadyStarted
|
|
}
|
|
s.stopCh = make(chan struct{})
|
|
return nil
|
|
}
|
|
|
|
func (s *stopper) Shutdown() {
|
|
if s.stopCh != nil {
|
|
close(s.stopCh)
|
|
s.stopCh = nil
|
|
}
|
|
}
|