func run(someChannel chan<- int, lights *lightsoff.LightsOff) { defer lights.TurnOff() defer println("Done") for i := 0; i < 100; i++ { someChannel <- i } }
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 wg.Add(50) defer wg.Wait() for i := 0; i < 50; i++ { go func() { defer wg.Done() lightsOff.TurnOff()