Пример #1
0
func main() {
	db := common.GetDBConnection()

	providerChan = make(chan *Provider) // unbuffered
	// fetch data
	go fetchData(db)
	// blocking calls
	useData()
	//useDataWorkerPool() // using a worker pool to interleave the tasks
}
Пример #2
0
func main() {
	db := common.GetDBConnection()
	providerChan = make(chan *Provider) // unbuffered data chan
	done = make(chan struct{})          // unbuffered control chan
	// fetch data
	go fetchData(db)
	go useData()
	// blocking call
	stop()
}
Пример #3
0
func main() {
	db := common.GetDBConnection()

	// bounded loop to simulate repeated fetches
	for i := 0; i <= 1; i++ {
		fmt.Println("Iteration ", i)
		providerChan = make(chan *Provider, 10) // buffered chan as we know the amount of data
		go fetchData(db)
		//blocking calls
		useData() // task order is more deterministic
		//useDataWorkerPool() // tasks are more interleaved
	}
}
Пример #4
0
func main() {
	db := common.GetDBConnection()
	// NOTIFY OMIT
	providerChan = make(chan *Provider) // unbuffered data chan
	quit = make(chan struct{})          // unbuffered control chans
	done = make(chan struct{})
	go fetchData(db)
	go useData()
	sig := make(chan os.Signal)
	signal.Notify(sig, syscall.SIGINT)
	<-sig
	stop()
	// NOTIFY OMIT
}