Skip to content

Commit a4a6cea

Browse files
committed
Updated task
1 parent 1857627 commit a4a6cea

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

plugin/pgqueue/task.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,15 @@ func (t *task) Run(ctx context.Context) error {
7171
}(ctx)
7272

7373
// Continue until context is done
74-
parent, cancel := context.WithCancel(ctx)
75-
defer cancel()
76-
go func() {
77-
// Context should be done when all goroutines have ended,
78-
// then cancel the runloop
74+
parent, parentCancel := context.WithCancel(context.Background())
75+
go func(ctx context.Context, parentCancel context.CancelFunc) {
76+
// Wait for the context to be done
77+
<-ctx.Done()
78+
// Wait for the goroutines to finish
7979
t.Wait()
80-
cancel()
81-
}()
80+
// Cancel the runLoop
81+
parentCancel()
82+
}(ctx, parentCancel)
8283

8384
// Runloop until the parent context is done
8485
FOR_LOOP:
@@ -188,7 +189,7 @@ func (t *task) exec(ctx context.Context, fn exec, in any) (result error) {
188189
}
189190

190191
// Concatenate any errors from the deadline
191-
if deadline.Err() != nil {
192+
if deadline.Err() != nil && !errors.Is(err, deadline.Err()) {
192193
result = errors.Join(result, deadline.Err())
193194
}
194195

0 commit comments

Comments
 (0)