wheat-cache/pkg/lru/worker.go

31 lines
674 B
Go
Raw Normal View History

2021-09-27 11:29:47 +08:00
package lru
import (
"context"
2021-10-07 16:30:56 +08:00
"gitee.com/timedb/wheatCache/pkg/errorx"
2021-09-27 11:29:47 +08:00
"gitee.com/timedb/wheatCache/pkg/event"
)
2021-10-04 22:37:21 +08:00
func (lru *SingleCache) lruSingleWork() interface{} {
2021-09-27 11:29:47 +08:00
ctx := context.Background()
for {
2021-10-04 16:25:52 +08:00
workEvent := lru.lruConsumer.Receive(ctx)
2021-09-27 11:29:47 +08:00
2021-10-07 16:30:56 +08:00
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
}
2021-09-27 11:29:47 +08:00
2021-10-07 16:30:56 +08:00
if work, ok := workFunc.(event.EventWorkFunc); ok {
workEvent.ExecWorkAndSendResult(work)
}
case CleanEventName:
2021-09-27 11:29:47 +08:00
}
}
}