diff --git a/pkg/lru/worker.go b/pkg/lru/worker.go index 99eb362..1120ca7 100644 --- a/pkg/lru/worker.go +++ b/pkg/lru/worker.go @@ -2,8 +2,8 @@ package lru import ( "context" + "gitee.com/timedb/wheatCache/pkg/errorx" "gitee.com/timedb/wheatCache/pkg/event" - "log" ) func (lru *SingleCache) lruSingleWork() interface{} { @@ -11,16 +11,20 @@ func (lru *SingleCache) lruSingleWork() interface{} { for { workEvent := lru.lruConsumer.Receive(ctx) - workFunc, ok := workEvent.GetValue(WorkFuncEventKey) - if !ok { - continue - } + switch workEvent.GetEventName() { + case OptionEventName: + workFunc, ok := workEvent.GetValue(WorkFuncEventKey) + if !ok { + workEvent.ExecWorkAndSendResult(func() (interface{}, error) { + return nil, errorx.New("the event haven't work of function") + }) + continue + } - switch workFunc.(type) { - case event.EventWorkFunc: - workEvent.ExecWorkAndSendResult(workFunc.(event.EventWorkFunc)) - default: - log.Print("this is debug ") + if work, ok := workFunc.(event.EventWorkFunc); ok { + workEvent.ExecWorkAndSendResult(work) + } + case CleanEventName: } } }