package dbservice import ( "go_dreamfactory/lego/core" "go_dreamfactory/lego/core/cbase" "time" ) type DBService_Comp struct { cbase.ModuleCompBase task chan string module *DBService } func (this *DBService_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { this.ModuleCompBase.Init(service, module, comp, options) this.module = module.(*DBService) return } func (this *DBService_Comp) Start() (err error) { err = this.ModuleCompBase.Start() go this.run() return } func (this *DBService_Comp) run() { for { select { case v := <-this.task: this.module.db_comp.Model_UpdateDBByLog(v) case <-time.After(time.Second * 2): this.module.db_comp.Model_UpdateDBByLog("") } } } func (this *DBService_Comp) PushUserTask(uid string) { this.task <- uid }