From 77de133cd363e933845362e223a16d58774874c8 Mon Sep 17 00:00:00 2001 From: David Rijsman Date: Fri, 26 Apr 2024 10:42:34 +0200 Subject: [PATCH] Cancel --- solve_solver.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/solve_solver.go b/solve_solver.go index 8f01254..db16c28 100644 --- a/solve_solver.go +++ b/solve_solver.go @@ -257,7 +257,6 @@ func (s *solveImpl) Solve( ctx, start.Add(solveOptions.Duration), ) - defer cancel() solveInformation := &solveInformationImpl{ iteration: 0, @@ -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++ { @@ -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) @@ -320,6 +323,7 @@ func (s *solveImpl) Solve( s.solveEvents.Iterated.Trigger(solveInformation) } s.solveEvents.Done.Trigger(solveInformation) + cancel() }() return solutions, err