-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:增加资源管理,能够在关闭时释放资源 fix:修复游戏达人启动chromedp资源无法及时释放
- Loading branch information
1 parent
395fb86
commit ffeb4ac
Showing
3 changed files
with
77 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package resource | ||
|
||
import "context" | ||
|
||
// ResourceManager 管理注册的资源释放函数 | ||
type resourceManager struct { | ||
cleanupFuncs []func(context.Context) error | ||
} | ||
|
||
// Register 注册释放资源的函数 | ||
func (rm *resourceManager) Register(cleanupFunc func(context.Context) error) { | ||
rm.cleanupFuncs = append(rm.cleanupFuncs, cleanupFunc) | ||
} | ||
|
||
// Cleanup 执行所有注册的释放函数 | ||
func (rm *resourceManager) Cleanup(ctx context.Context) error { | ||
for _, cleanup := range rm.cleanupFuncs { | ||
if err := cleanup(ctx); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
var ResourceManager = &resourceManager{} |