示例#1
0
func run(someChannel chan<- int, lights *lightsoff.LightsOff) {
	defer lights.TurnOff()
	defer println("Done")

	for i := 0; i < 100; i++ {
		someChannel <- i
	}
}
示例#2
0
package lightsoff_test

import (
	"sync"

	"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()
			}()
		}