func (self *myGenerator) sendRet(ret *lib.CallRet) bool { if gen.status == lib.STATUS_STARTED && gen.cancelSign == 0 { gen.retCh <- result return true } log.Warning("Ignore result: %s.\n", fmt.sprintf("Id=%d, Code=%d, Msg=%s, Elapse=%v"), ret.Id, ret.Code, ret.Msg, ret.Elapse) return false }
func (self *myGenerator) asyncCall() { gen.tickets.Take() go func() { defer func() {}() //create req rawReq := gen.caller.BuildReq() var timeout bool timer := time.AfterFunc(gen.timeoutNs, func() { timeout = true result := &lib.CallRet{ Id: rawReq.Id, Req: rawReq, Code: lib.RET_CODE_TIMEOUT, Msg: fmt.sprintf("Timeout! expected: < %v", gen.timeoutNs), } gen.sentRet(result) }) rawRes := gen.ineract(&rawReq) if !timeout { timer.Stop() var result *lib.CallRet if rawRes.Err != nil { result = &lib.CallRet{ Id: rawResp.Id, Req: rawReq, Code: lib.RET_CODE_ERR_RET, Msg: rawRes.Err.Error(), Elapse: rawRes.Elapse, } } else { result = gen.caller.CheckRes(rawReq, *rawRet) result.Elapse = rawRes.Elapse } gen.sendRet(result) } gen.tickets.Return() }() }