grtm
grtm copied to clipboard
Why not quit
` type MyCtx struct { A int B int }
func setup1(ctx MyCtx) error { for i := 0 ; i < 1; i++ { fmt.Println("setup1", ctx.A, ctx.B) time.Sleep(1time.Second) } return nil }
func setup2(ctx MyCtx) error { for i := 0 ; i < 2; i++ { fmt.Println("setup2", ctx.A, ctx.B) time.Sleep(1time.Second) } return nil }
func setup3(ctx MyCtx) error { for i := 0 ; i < 3; i++ { fmt.Println("setup3", ctx.A, ctx.B) time.Sleep(1time.Second) } return nil }
var tasks = []func(*MyCtx) error{ setup1, setup2, setup3, }
func funcWithParams(arg interface{}) { ctx := arg.(MyCtx)
for _, task := range tasks {
task(&ctx)
}
}
func main() { gm := grtm.NewGrManager() ctx :=MyCtx{ A: 1, B: 2, } gm.NewGoroutine("funcWithParams", funcWithParams, ctx) time.Sleep(time.Second * 3) gm.StopLoopGoroutine("funcWithParams") } `
setup1 1 2 setup2 1 2 setup2 1 2 setup3 1 2 setup3 1 2 setup3 1 2
main func not quit yet!!