Improve solver channel management according to @aluzzardi comments

Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
Tom Chauveau
2021-08-23 16:57:19 +02:00
parent 95468ce2b3
commit 3f0350359e
2 changed files with 47 additions and 46 deletions

View File

@@ -170,26 +170,17 @@ func (c *Client) buildfn(ctx context.Context, st *state.State, env *environment.
go catchOutput(buildCh)
resp, err := c.c.Build(ctx, opts, "", func(ctx context.Context, gw bkgw.Client) (*bkgw.Result, error) {
eventsWg := sync.WaitGroup{}
closeCh := make(chan *bk.SolveStatus)
s := solver.New(solver.Opts{
Control: c.c,
Gateway: gw,
Events: eventsCh,
Auth: auth,
Secrets: secrets,
NoCache: c.cfg.NoCache,
})
// Close events channel
defer func() {
close(closeCh)
eventsWg.Wait()
close(eventsCh)
}()
s := solver.New(solver.Opts{
Control: c.c,
Gateway: gw,
Events: eventsCh,
EventsWg: &eventsWg,
CloseEvent: closeCh,
Auth: auth,
Secrets: secrets,
NoCache: c.cfg.NoCache,
})
defer s.Stop()
// Compute output overlay
if fn != nil {