Add cancellation after read and before write, to be able to cancel operation more quickly

This commit is contained in:
eleksir
2026-04-04 15:22:50 +03:00
parent 6955e14921
commit c1444f8c1d

View File

@@ -227,6 +227,12 @@ func copyWithContext(ctx context.Context, dst io.Writer, src io.Reader) error {
n, readErr := src.Read(buf)
if n > 0 {
select {
case <-ctx.Done():
return ctx.Err()
default:
}
if _, werr := dst.Write(buf[:n]); werr != nil {
return werr
}