go-pattern-examples/creation/04_object_pool/obejct_poo.go

32 lines
436 B
Go
Raw Normal View History

2020-04-24 13:09:58 +03:00
package objectpool
2020-05-05 17:59:18 +03:00
import (
"fmt"
"strconv"
)
2020-04-24 13:09:58 +03:00
type doctor struct {
name string
2020-05-05 17:59:18 +03:00
kind int //科室,1内科2外科
2020-04-24 13:09:58 +03:00
}
type pool chan *doctor
func newPool(total int) pool {
p := make(pool, total)
for i := 0; i < total; i++ {
2020-05-05 17:59:18 +03:00
dc := new(doctor)
dc.name = "doctor: " + strconv.Itoa(i)
p <- dc
2020-04-24 13:09:58 +03:00
}
return p
}
//surgery
2020-05-05 17:59:18 +03:00
func (d doctor) surgery(someone string) {
fmt.Println("doctor:", d.name, "do surgery for", someone)
2020-04-24 13:09:58 +03:00
}