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() { 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) } s.commandServer = chanrpc.NewServer(0) }
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 }