Ejemplo n.º 1
0
func init() {
	time.AfterFunc(time.Second*5, func() {
		var i int
		h, b := timer.StartTimer(timer.TimerActionWrapper(func(h timer.TimerHandle, ud interface{}) bool {
			i++
			fmt.Println(i, time.Now())
			return true
		}), nil, time.Second, 10)
		fmt.Println("timer lauch ", h, b)
	})
}
Ejemplo n.º 2
0
func (this *transactCoordinater) createTransNode(tnp *TransNodeParam, ud interface{}, timeout time.Duration) *TransNode {
	if this == nil || tnp == nil {
		logger.Warn("transactCoordinater.createTransNode failed, Null Pointer")
		return nil
	}
	if this.quit {
		logger.Warn("transactCoordinater.createTransNode failed, module shutdowning")
		return nil
	}
	transHandler := GetHandler(tnp.Tt)
	if transHandler == nil {
		logger.Warn("transactCoordinater.createTransNode failed, TransNodeParam=%v", *tnp)
		return nil
	}

	if tnp.TId == TransNodeIDNil {
		tnp.TId = this.spawnTransNodeID()
	}

	if Config.tcs != nil {
		tnp.SkeletonID = Config.tcs.GetSkeletonID()
		tnp.AreaID = Config.tcs.GetAreaID()
	}
	tnp.TimeOut = timeout
	tnode := &TransNode{
		MyTnp:    tnp,
		handler:  transHandler,
		owner:    this,
		TransRep: &TransResult{},
		TransEnv: NewTransCtx(),
		ud:       ud,
	}

	this.addTransNode(tnode)

	if h, ok := timer.StartTimer(tta, tnode, timeout, 1); ok {
		tnode.timeHandle = h
	} else {
		return nil
	}
	return tnode
}