You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

41 lines
965 B

package coordinator
import (
"context"
"github.com/hermeznetwork/hermez-node/common"
"github.com/hermeznetwork/hermez-node/log"
"github.com/hermeznetwork/hermez-node/prover"
"github.com/hermeznetwork/tracerr"
)
// ProversPool contains the multiple prover clients
type ProversPool struct {
pool chan prover.Client
}
// NewProversPool creates a new pool of provers.
func NewProversPool(maxServerProofs int) *ProversPool {
return &ProversPool{
pool: make(chan prover.Client, maxServerProofs),
}
}
// Add a prover to the pool
func (p *ProversPool) Add(ctx context.Context, serverProof prover.Client) {
select {
case p.pool <- serverProof:
case <-ctx.Done():
}
}
// Get returns the next available prover
func (p *ProversPool) Get(ctx context.Context) (prover.Client, error) {
select {
case <-ctx.Done():
log.Info("ServerProofPool.Get done")
return nil, tracerr.Wrap(common.ErrDone)
case serverProof := <-p.pool:
return serverProof, nil
}
}