func main() { someChannel := make(chan int, 10) count := 5 lights := lightsoff.New(count, func() { close(someChannel) }) for i := 0; i < count; i++ { go run(someChannel, lights) } for range someChannel { //NOP } }
"github.com/apoydence/lightsoff" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("Lightsoff", func() { var ( lightsOff *lightsoff.LightsOff funcCalled chan struct{} ) BeforeEach(func() { funcCalled = make(chan struct{}) lightsOff = lightsoff.New(5, func() { close(funcCalled) }) }) It("calls the callback function once everyone is done", func() { for i := 0; i < 5; i++ { go func() { lightsOff.TurnOff() }() } Eventually(funcCalled).Should(BeClosed()) }) It("calls the callback only once", func() { var wg sync.WaitGroup