refactor(worker): refactor

This commit is contained in:
HuangJiaLuo 2021-10-07 16:30:56 +08:00
parent e3171a8b3e
commit 83febdd482
1 changed files with 14 additions and 10 deletions

View File

@ -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:
}
}
}