Skip to content

Commit

Permalink
f_com_del:add del component func
Browse files Browse the repository at this point in the history
Signed-off-by: zhangjiulong <[email protected]>
  • Loading branch information
kowloonzh committed Sep 19, 2019
1 parent 26b76b6 commit d0c50af
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions com.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"sync"
)

type Components struct {
type components struct {
m sync.Map
}

func (c *Components) Ins(key string, f func() interface{}) interface{} {
func (c *components) Ins(key string, f func() interface{}) interface{} {
// @todo 监听配置重载信号
v, ok := c.m.Load(key)
if !ok {
Expand All @@ -19,6 +19,15 @@ func (c *Components) Ins(key string, f func() interface{}) interface{} {

}

var Component = new(Components)
func (c *components) Del(key string, cb ...func()) {
c.m.Delete(key)

if len(cb) > 0 {
// 执行回调关闭链接
go cb[0]()
}
}

var Component = new(components)

// example @see coms/kafka

0 comments on commit d0c50af

Please sign in to comment.