Categorygithub.com/rxwen/resourcepool
modulepackage
1.0.6
Repository: https://github.com/rxwen/resourcepool.git
Documentation: pkg.go.dev

# README

wercker status

resourcepool is a pool for resource management. It can be used to manage resources like database connections, redis connections, thrift connections. It has following features:

  • support multiple backend servers
  • support backend server replacement on the fly

Example

	pool, err := resourcepool.NewResourcePool("fakehost", "9090", func(host, port string) (interface{}, error) {
		log.Println("create new resource")
		return &FakeResource{}, nil
	}, func(r interface{}) error {
		log.Println("close resource ")
		log.Println(r)
		return nil
	}, 3, 1)

    destroy := false
	r1, _ := pool.Get()
	r2, _ := pool.Get()
	con, _ := pool.Get()
	defer func() { pool.Putback(r1, destroy) }() // use a func to wrap the putback to avoid evalute destroy value now
	defer func() { pool.Putback(r2, destroy) }()
	defer func() { pool.Putback(con, destroy) }()
    // use resource

    // if any error found during use the resource, and the resource is deemed not reuseable anymore, set destroy flag
    // to ture, indicate the resource shall not be managed by resource pool anymore
    // an example is, our code get a network connection from the pool, but found the connection is broken and it should
    // not be putback to the pool
    destroy = true

# Packages

Package databasepool provides ...
Package main provides ...
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

AddServer adds a new server to the pool.

# Structs

No description provided by the author

# Type aliases

ClientCloseFunc is the function used for closing client.
ClientCreationFunc is the function used for creating new client.