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.
 
 
 

38 lines
905 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(serverProof prover.Client) {
p.pool <- serverProof
}
// 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
}
}