Ejemplo n.º 1
0
func work(i int) {
	fmt.Println("Start Work id: ", i)
	P := pool.Name("db")
	resource := P.Acquire() // obtain the resource
	if resource == nil {
		fmt.Println("Not enough resources to run: ", i)
	} else {
		if i%2 == 0 {
			time.Sleep(time.Microsecond * 1)
		} else {
			time.Sleep(time.Microsecond * 2)
		}
		fmt.Println("Work id: ", i, " Resource id: ", resource)
		P.Release(resource)
		fmt.Println("End Work id: ", i)
	}
}
Ejemplo n.º 2
0
func final() {
	P := pool.Name("db")
	P.Drain() // free up all resources
}