github.com/chenbh/concourse/v6@v6.4.2/atc/wrappa/pool.go (about)

     1  package wrappa
     2  
     3  import (
     4  	"golang.org/x/sync/semaphore"
     5  )
     6  
     7  //go:generate counterfeiter . Pool
     8  
     9  type Pool interface {
    10  	Size() int
    11  	TryAcquire() bool
    12  	Release()
    13  }
    14  
    15  type pool struct {
    16  	*semaphore.Weighted
    17  	size int
    18  }
    19  
    20  func NewPool(size int) Pool {
    21  	return &pool{
    22  		Weighted: semaphore.NewWeighted(int64(size)),
    23  		size:     size,
    24  	}
    25  }
    26  
    27  func (p *pool) Size() int {
    28  	return p.size
    29  }
    30  
    31  func (p *pool) TryAcquire() bool {
    32  	return p.Weighted.TryAcquire(1)
    33  }
    34  
    35  func (p *pool) Release() {
    36  	p.Weighted.Release(1)
    37  }