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

  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(ctx context.Context, serverProof prover.Client) {
  21. select {
  22. case p.pool <- serverProof:
  23. case <-ctx.Done():
  24. }
  25. }
  26. // Get returns the next available prover
  27. func (p *ProversPool) Get(ctx context.Context) (prover.Client, error) {
  28. select {
  29. case <-ctx.Done():
  30. log.Info("ServerProofPool.Get done")
  31. return nil, tracerr.Wrap(common.ErrDone)
  32. case serverProof := <-p.pool:
  33. return serverProof, nil
  34. }
  35. }