Return ctx.Err() on ctx.Done()

This commit is contained in:
Alexander A. Klimov 2021-03-26 12:17:16 +01:00
parent 5e473e8b37
commit 0ec2b6ca60
4 changed files with 8 additions and 6 deletions

View file

@ -50,7 +50,7 @@ func (b *Bulker) run(ch <-chan contracts.Entity, count int) {
bufCh <- v
case <-ctx.Done():
return nil
return ctx.Err()
}
}
})
@ -74,7 +74,7 @@ func (b *Bulker) run(ch <-chan contracts.Entity, count int) {
case <-timeout:
drain = false
case <-ctx.Done():
return nil
return ctx.Err()
}
}

View file

@ -46,7 +46,7 @@ func (d Driver) Open(dsn string) (c driver.Conn, err error) {
select {
case <-ctx.Done():
// Context canceled.
return
return nil, ctx.Err()
case <-time.After(sleep):
// Wait for backoff duration and continue.
}

View file

@ -80,7 +80,7 @@ func (delta *Delta) start(ctx context.Context, actualCh, desiredCh <-chan contra
cnt.Inc()
case <-ctx.Done():
return nil
return ctx.Err()
}
}
})
@ -116,7 +116,7 @@ func (delta *Delta) start(ctx context.Context, actualCh, desiredCh <-chan contra
cnt.Inc()
case <-ctx.Done():
return nil
return ctx.Err()
}
}
})

View file

@ -30,7 +30,9 @@ func WithBackoff(ctx context.Context, retryableFunc RetryableFunc, retryable IsR
select {
case <-ctx.Done():
// Context canceled. Return last known error.
// TODO(el): Return ctx.Err() if err is nil?
if err == nil {
err = ctx.Err()
}
return
case <-time.After(sleep):
// Wait for backoff duration and continue.