Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pool ¶
Example ¶
var pool, err = New(func(ctx context.Context) (io.Closer, error) { return net.Dial("tcp", "baidu.com:80") }, func(ctx context.Context, r *Resource) bool { if time.Since(r.IdleAt) < time.Minute { return true } // check if r.Resource() is usable, may be by a ping or noop operation return true }, 5, 2) if err != nil { panic(err) } // this can also be doing concurrently for i := 0; i < 10; i++ { ctx, _ := context.WithTimeout(context.Background(), 5*time.Second) // get a connection resource, err := pool.Get(ctx) if err != nil { panic(err) } // do some work with the connection ... conn := resource.Resource().(net.Conn) conn.Write(nil) // put the connection back if err := pool.Put(resource); err != nil { panic(err) } }
Output:
func New2 ¶
New2 return a pool by params from url.Values. Params default value: maxOpen => 10; maxIdle => 1;
Click to show internal directories.
Click to hide internal directories.