2017-03-05 07:56:08 +00:00
|
|
|
package docker
|
|
|
|
|
|
|
|
// import (
|
2021-10-12 07:25:13 +00:00
|
|
|
|
2017-03-05 07:56:08 +00:00
|
|
|
// )
|
|
|
|
//
|
|
|
|
// // Pool manages a pool of Docker clients.
|
|
|
|
// type Pool struct {
|
|
|
|
// queue chan (backend.Engine)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // NewPool returns a Pool.
|
|
|
|
// func NewPool(engines ...backend.Engine) *Pool {
|
|
|
|
// return &Pool{
|
|
|
|
// queue: make(chan backend.Engine, len(engines)),
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // Reserve requests the next available Docker client in the pool.
|
|
|
|
// func (p *Pool) Reserve(c context.Context) backend.Engine {
|
|
|
|
// select {
|
|
|
|
// case <-c.Done():
|
2021-11-27 01:29:14 +00:00
|
|
|
// case docker := <-p.queue:
|
|
|
|
// return docker
|
2017-03-05 07:56:08 +00:00
|
|
|
// }
|
|
|
|
// return nil
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // Release releases the Docker client back to the pool.
|
2021-11-27 01:29:14 +00:00
|
|
|
// func (p *Pool) Release(docker backend.Engine) {
|
|
|
|
// p.queue <- docker
|
2017-03-05 07:56:08 +00:00
|
|
|
// }
|
|
|
|
|
|
|
|
// pool := docker.Pool(
|
|
|
|
// docker.FromEnvironmentMust(),
|
|
|
|
// docker.FromEnvironmentMust(),
|
|
|
|
// docker.FromEnvironmentMust(),
|
|
|
|
// docker.FromEnvironmentMust(),
|
|
|
|
// )
|
|
|
|
//
|
|
|
|
// client := pool.Reserve()
|
|
|
|
// defer pool.Release(client)
|