grtm icon indicating copy to clipboard operation
grtm copied to clipboard

Why not quit

Open wangxin0814 opened this issue 3 years ago • 0 comments

` 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!!

wangxin0814 avatar Dec 10 '21 07:12 wangxin0814