Skip to content

jameswei/go-commons-pool

 
 

Repository files navigation

Go Commons Pool

Build Status Circle CI Coverage Status GoDoc

The Go Commons Pool is a Go generic object pool, direct translate from Apache Commons Pool.

Features

Usage

//use create func
pool := NewObjectPoolWithDefaultConfig(NewPooledObjectFactorySimple(
		func() (interface{}, error) {
			return &MyPoolObject{}, nil
		}))
obj, _ := pool.BorrowObject()
pool.ReturnObject(obj)
	
//use custom Object factory

type MyObjectFactory struct {
	
}

func (this *MyObjectFactory) MakeObject() (*PooledObject, error) {
	return NewPooledObject(&MyPoolObject{}), nil
}

func (this *MyObjectFactory) DestroyObject(object *PooledObject) error {
	//do destroy
	return nil
}

func (this *MyObjectFactory) ValidateObject(object *PooledObject) bool {
	//do validate
	return true
}

func (this *MyObjectFactory) ActivateObject(object *PooledObject) error {
	//do activate
	return nil
}

func (this *MyObjectFactory) PassivateObject(object *PooledObject) error {
	//do passivate
	return nil
}

pool := NewObjectPoolWithDefaultConfig(new(MyObjectFactory))
obj, _ := pool.BorrowObject()
pool.ReturnObject(obj)

How to contribute

  • Choose one open issue you want to solve, if not create one and describe what you want to change.
  • Fork the repository on GitHub.
  • Write code to solve the issue.
  • Create PR and link to the issue.
  • Make sure test and coverage pass.
  • Wait maintainers to merge.

License

Go Commons Pool is available under the Apache License, Version 2.0.

About

a Go generic object pool

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%