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

  1. package coordinator
  2. import (
  3. "context"
  4. "github.com/hermeznetwork/hermez-node/common"
  5. "github.com/hermeznetwork/hermez-node/log"
  6. "github.com/hermeznetwork/hermez-node/prover"
  7. "github.com/hermeznetwork/tracerr"
  8. )
  9. // ProversPool contains the multiple prover clients
  10. type ProversPool struct {
  11. pool chan prover.Client
  12. }
  13. // NewProversPool creates a new pool of provers.
  14. func NewProversPool(maxServerProofs int) *ProversPool {
  15. return &ProversPool{
  16. pool: make(chan prover.Client, maxServerProofs),
  17. }
  18. }
  19. // Add a prover to the pool
  20. func (p *ProversPool) Add(serverProof prover.Client) {
  21. p.pool <- serverProof
  22. }
  23. // Get returns the next available prover
  24. func (p *ProversPool) Get(ctx context.Context) (prover.Client, error) {
  25. select {
  26. case <-ctx.Done():
  27. log.Info("ServerProofPool.Get done")
  28. return nil, tracerr.Wrap(common.ErrDone)
  29. case serverProof := <-p.pool:
  30. return serverProof, nil
  31. }
  32. }