blob: 2571012a9f323bc838d89a6b3c234f67e4a16301 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
package acme
import (
"errors"
"time"
)
// Solver decribes a solving interface
type Solver interface {
Solve() error
Abort() error
}
var canSolve = make(map[ChallengeType]bool)
var errTimeOut = errors.New("time out")
func registerChallenge(c ChallengeType) {
canSolve[c] = true
}
func Solve(s Solver, timeout time.Duration) error {
errc := make(chan error)
go func() {
errc <- s.Solve()
}()
select {
case err := <-errc:
return err
case <-time.After(timeout):
s.Abort()
return errTimeOut
}
}
|