Skip to content

Commit

Permalink
Cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
David Rijsman committed Apr 26, 2024
1 parent 3610a15 commit 77de133
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions solve_solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ func (s *solveImpl) Solve(
ctx,
start.Add(solveOptions.Duration),
)
defer cancel()

solveInformation := &solveInformationImpl{
iteration: 0,
Expand All @@ -278,7 +277,10 @@ func (s *solveImpl) Solve(
Error: nil,
}
go func() {
defer close(solutions)
defer func() {
close(solutions)
cancel()
}()

Loop:
for iteration := 0; iteration < solveOptions.Iterations; iteration++ {
Expand All @@ -295,6 +297,7 @@ func (s *solveImpl) Solve(
select {
case <-ctx.Done():
s.solveEvents.ContextDone.Trigger(solveInformation)
cancel()
break Loop
default:
improved, e := s.invoke(ctx, solveOperator, solveInformation)
Expand All @@ -320,6 +323,7 @@ func (s *solveImpl) Solve(
s.solveEvents.Iterated.Trigger(solveInformation)
}
s.solveEvents.Done.Trigger(solveInformation)
cancel()
}()

return solutions, err
Expand Down

0 comments on commit 77de133

Please sign in to comment.