Initial commit

This commit is contained in:
Donny
2019-04-22 20:46:32 +08:00
commit 49ab8aadd1
25441 changed files with 4055000 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
package ctrl
import (
"context"
"reflect"
"runtime"
"sync"
"go-common/library/log"
)
func NewUnboundedExecutor() *UnboundedExecutor {
ctx := context.Background()
return &UnboundedExecutor{
ctx: ctx,
}
}
type UnboundedExecutor struct {
wg sync.WaitGroup
// for future extension
ctx context.Context
}
type Executor interface {
Submit(bizFunc ...func(ctx context.Context))
}
func (executor *UnboundedExecutor) Submit(bizFunc ...func(c context.Context)) {
for _, biz := range bizFunc {
pc := reflect.ValueOf(biz).Pointer()
funcName := runtime.FuncForPC(pc).Name()
executor.wg.Add(1)
go func(funcName string, biz func(ctx context.Context)) {
defer executor.wg.Done()
log.Info("Exec Task %s", funcName)
biz(executor.ctx)
}(funcName, biz)
}
}