func (s *Skeleton) Init() { if s.GoLen <= 0 { s.GoLen = 0 } if s.TimerDispatcherLen <= 0 { s.TimerDispatcherLen = 0 } s.g = g.New(s.GoLen) s.dispatcher = timer.NewDispatcher(s.TimerDispatcherLen) s.server = s.ChanRPCServer if s.server == nil { s.server = chanrpc.NewServer(0) } }
func ExampleCron() { d := timer.NewDispatcher(10) // cron var c *timer.Cron c, _ = d.CronFunc("* * * * * *", func() { fmt.Println("My name is Leaf") c.Stop() }) // dispatch (<-d.ChanTimer).Cb() // Output: // My name is Leaf }
//初始化 func (s *Skeleton) Init() { //检查Go管道长度 if s.GoLen <= 0 { s.GoLen = 0 } //检查定时器分发器管道长度 if s.TimerDispatcherLen <= 0 { s.TimerDispatcherLen = 0 } s.g = g.New(s.GoLen) //创建Go s.dispatcher = timer.NewDispatcher(s.TimerDispatcherLen) //创建分发器 s.server = s.ChanRPCServer //外部传入的,内部引用 if s.server == nil { //外部传入的为空 s.server = chanrpc.NewServer(0) //内部创建一个 } s.commandServer = chanrpc.NewServer(0) //创建命令RPC服务器 }
func ExampleTimer() { d := timer.NewDispatcher(10) // timer 1 d.AfterFunc(1, func() { fmt.Println("My name is Leaf") }) // timer 2 t := d.AfterFunc(1, func() { fmt.Println("will not print") }) t.Stop() // dispatch (<-d.ChanTimer).Cb() // Output: // My name is Leaf }
func (s *Skeleton) Init() { if s.GoLen <= 0 { s.GoLen = 0 } if s.TimerDispatcherLen <= 0 { s.TimerDispatcherLen = 0 } if s.AsynCallLen <= 0 { s.AsynCallLen = 0 } s.g = g.New(s.GoLen) s.dispatcher = timer.NewDispatcher(s.TimerDispatcherLen) s.client = chanrpc.NewClient(s.AsynCallLen) s.server = s.ChanRPCServer if s.server == nil { s.server = chanrpc.NewServer(0) } s.commandServer = chanrpc.NewServer(0) }
func ExampleCron() { d := timer.NewDispatcher(10) // cron expr cronExpr, err := timer.NewCronExpr("* * * * * *") if err != nil { return } // cron var c *timer.Cron c = d.CronFunc(cronExpr, func() { fmt.Println("My name is Leaf") c.Stop() }) // dispatch (<-d.ChanTimer).Cb() // Output: // My name is Leaf }