Skip to content

Commit

Permalink
refine concurrent flow
Browse files Browse the repository at this point in the history
  • Loading branch information
amyangfei committed May 8, 2019
1 parent 3510fb2 commit da20216
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions pkg/hello/hello.go
Expand Up @@ -79,18 +79,15 @@ func Boundary() {
})
}()

go func() {
time.Sleep(time.Second * 300)
fmt.Println("after long sleep 4")
}()

go func() {
fmt.Println("before sleep 1")
time.Sleep(time.Second * 300)
fmt.Println("after long sleep 1")
}()

wg.Add(1)
go func(cctx context.Context) {
defer wg.Done()
fmt.Println("before sleep 2")
select {
case <-cctx.Done():
Expand All @@ -101,12 +98,10 @@ func Boundary() {
fmt.Println("after long sleep 2")
}(ctx)

wg.Add(1)
go func() {
defer wg.Done()
time.Sleep(time.Millisecond * 100)
cancel()
}()

wg.Wait()
cancel()
}

0 comments on commit da20216

Please sign in to comment.