2018-12-11 22:01:50 +01:00
|
|
|
package frameconn
|
|
|
|
|
|
|
|
import "sync"
|
|
|
|
|
|
|
|
type shutdownFSM struct {
|
2019-03-22 19:41:12 +01:00
|
|
|
mtx sync.Mutex
|
|
|
|
state shutdownFSMState
|
2018-12-11 22:01:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type shutdownFSMState uint32
|
|
|
|
|
|
|
|
const (
|
2019-03-22 20:45:27 +01:00
|
|
|
// zero value is important
|
2018-12-11 22:01:50 +01:00
|
|
|
shutdownStateOpen shutdownFSMState = iota
|
|
|
|
shutdownStateBegin
|
|
|
|
)
|
|
|
|
|
|
|
|
func (f *shutdownFSM) Begin() (thisCallStartedShutdown bool) {
|
|
|
|
f.mtx.Lock()
|
|
|
|
defer f.mtx.Unlock()
|
|
|
|
thisCallStartedShutdown = f.state != shutdownStateOpen
|
|
|
|
f.state = shutdownStateBegin
|
|
|
|
return thisCallStartedShutdown
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *shutdownFSM) IsShuttingDown() bool {
|
|
|
|
f.mtx.Lock()
|
|
|
|
defer f.mtx.Unlock()
|
|
|
|
return f.state != shutdownStateOpen
|
|
|
|
}
|