feat: implement confirmer

This commit is contained in:
James Houlahan
2020-07-23 13:38:06 +02:00
parent be20714842
commit c8f118a26b
5 changed files with 133 additions and 0 deletions

36
pkg/confirmer/request.go Normal file
View File

@ -0,0 +1,36 @@
package confirmer
import (
"errors"
"time"
"github.com/google/uuid"
)
type Request struct {
uuid string
value chan bool
timeout time.Duration
}
func newRequest(timeout time.Duration) *Request {
return &Request{
uuid: uuid.New().String(),
value: make(chan bool),
timeout: timeout,
}
}
func (r *Request) ID() string {
return r.uuid
}
func (r *Request) Result() (bool, error) {
select {
case res := <-r.value:
return res, nil
case <-time.After(r.timeout):
return false, errors.New("timed out waiting for result")
}
}