@@ -6,76 +6,46 @@ import (
6
6
"github.com/moby/buildkit/solver/pb"
7
7
"github.com/moby/buildkit/util/flightcontrol"
8
8
digest "github.com/opencontainers/go-digest"
9
- "github.com/pkg/errors"
10
9
)
11
10
12
11
type asyncState struct {
13
- f func (context.Context , State , * Constraints ) (State , error )
14
- prev State
15
- target State
16
- set bool
17
- err error
18
- g flightcontrol.Group [State ]
12
+ f func (context.Context , State , * Constraints ) (State , error )
13
+ prev State
14
+ g flightcontrol.CachedGroup [State ]
19
15
}
20
16
21
17
func (as * asyncState ) Output () Output {
22
18
return as
23
19
}
24
20
25
21
func (as * asyncState ) Vertex (ctx context.Context , c * Constraints ) Vertex {
26
- err := as .Do (ctx , c )
22
+ target , err := as .Do (ctx , c )
27
23
if err != nil {
28
24
return & errVertex {err }
29
25
}
30
- if as .set {
31
- out := as .target .Output ()
32
- if out == nil {
33
- return nil
34
- }
35
- return out .Vertex (ctx , c )
26
+ out := target .Output ()
27
+ if out == nil {
28
+ return nil
36
29
}
37
- return nil
30
+ return out . Vertex ( ctx , c )
38
31
}
39
32
40
33
func (as * asyncState ) ToInput (ctx context.Context , c * Constraints ) (* pb.Input , error ) {
41
- err := as .Do (ctx , c )
34
+ target , err := as .Do (ctx , c )
42
35
if err != nil {
43
36
return nil , err
44
37
}
45
- if as .set {
46
- out := as .target .Output ()
47
- if out == nil {
48
- return nil , nil
49
- }
50
- return out .ToInput (ctx , c )
38
+ out := target .Output ()
39
+ if out == nil {
40
+ return nil , nil
51
41
}
52
- return nil , nil
42
+ return out . ToInput ( ctx , c )
53
43
}
54
44
55
- func (as * asyncState ) Do (ctx context.Context , c * Constraints ) error {
56
- _ , err := as .g .Do (ctx , "" , func (ctx context.Context ) (State , error ) {
57
- if as .set {
58
- return as .target , as .err
59
- }
60
- res , err := as .f (ctx , as .prev , c )
61
- if err != nil {
62
- select {
63
- case <- ctx .Done ():
64
- if errors .Is (err , context .Cause (ctx )) {
65
- return res , err
66
- }
67
- default :
68
- }
69
- }
70
- as .target = res
71
- as .err = err
72
- as .set = true
73
- return res , err
45
+ func (as * asyncState ) Do (ctx context.Context , c * Constraints ) (State , error ) {
46
+ return as .g .Do (ctx , "" , func (ctx context.Context ) (State , error ) {
47
+ return as .f (ctx , as .prev , c )
74
48
})
75
- if err != nil {
76
- return err
77
- }
78
- return as .err
79
49
}
80
50
81
51
type errVertex struct {
0 commit comments