mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-23 01:08:47 +02:00
refactor: clean up code and fix race condition in idlewatcher
This commit is contained in:
39
internal/docker/idlewatcher/state.go
Normal file
39
internal/docker/idlewatcher/state.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package idlewatcher
|
||||
|
||||
func (w *Watcher) running() bool {
|
||||
return w.state.Load().running
|
||||
}
|
||||
|
||||
func (w *Watcher) ready() bool {
|
||||
return w.state.Load().ready
|
||||
}
|
||||
|
||||
func (w *Watcher) error() error {
|
||||
return w.state.Load().err
|
||||
}
|
||||
|
||||
func (w *Watcher) setReady() {
|
||||
w.state.Store(&containerState{
|
||||
running: true,
|
||||
ready: true,
|
||||
})
|
||||
}
|
||||
|
||||
func (w *Watcher) setStarting() {
|
||||
w.state.Store(&containerState{
|
||||
running: true,
|
||||
ready: false,
|
||||
})
|
||||
}
|
||||
|
||||
func (w *Watcher) setNapping() {
|
||||
w.setError(nil)
|
||||
}
|
||||
|
||||
func (w *Watcher) setError(err error) {
|
||||
w.state.Store(&containerState{
|
||||
running: false,
|
||||
ready: false,
|
||||
err: err,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user