Ejemplo n.º 1
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	tw := common.NewTimeWheel(50*time.Millisecond, 20, 500)

	db := common.NewMongo()
	hars := common.GetAllStatusApiOfUser(db, "db46161c-917a-40d8-b1fd-242e7cc8f4b3")
	fmt.Println(hars.Len())

	for e := hars.Front(); e != nil; e = e.Next() {
		element := e.Value
		h := element.(*common.StatusAPI)
		fmt.Printf("%+v\n", h)

		taskId, _ := tw.Loop(2*time.Second, do(h))
		fmt.Println("开启任务", taskId, h.HarId)
	}

	select {}
}
Ejemplo n.º 2
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	tw := common.NewTimeWheel(50*time.Millisecond, 20, 500)

	//	taskId, err := tw.After(3*time.Second, get)
	//	fmt.Println(taskId, err)

	//	var taskId int64
	for i := 0; i < 20; i++ {
		//time.Sleep(2*time.Second)

		_, _ = tw.Loop(1*time.Second, loop(i))
		//fmt.Println("taskId", taskId, "start")
	}

	//	go func(){//打印监控
	//		ticker := time.NewTicker(1 * time.Second)
	//		for {
	//			select {
	//			case <-ticker.C:
	//				fmt.Println(tw.Monitor())
	//			}
	//		}
	//	}()

	//	select {
	//	case <- time.After(10*time.Second):
	//		fmt.Println("remove",taskId)
	//		tw.Remove(taskId)
	//	case <- time.After(15*time.Second):
	//		tw.Loop(4*time.Second, loop)
	//	}

	select {}

}