1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-17 16:12:42 +08:00
Files
go-mixed/cleanup_guard/cleanup_guard.go
2022-07-26 14:15:13 +08:00

25 lines
358 B
Go

package cleanupguard
import "sync"
type CleanupGuard struct {
enable bool
fn func()
mutex sync.Mutex
}
// 新建清理
func NewCleanupGuard(fn func()) CleanupGuard {
return CleanupGuard{fn: fn, enable: true}
}
func (g *CleanupGuard) Enable() {
g.mutex.Lock()
defer g.mutex.Unlock()
g.enable = true
}
func (g *CleanupGuard) Run() {
g.fn()
}