How to wait until buffered channel (semaphore) is empty?

前端 未结 4 1883
遥遥无期
遥遥无期 2020-12-19 02:36

I have a slice of integers, which are manipulated concurrently:

ints := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

I\'m using a buffered channel

4条回答
  •  独厮守ぢ
    2020-12-19 03:01

    Clearly there is no one waiting for your go-routines to complete. Thus the program ends before the last 2 go-routines are completed. You may use a workgroup to wait for all your go-routines complete before the program ends. This tells it better - https://nathanleclaire.com/blog/2014/02/15/how-to-wait-for-all-goroutines-to-finish-executing-before-continuing/

提交回复
热议问题