mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-25 17:52:02 +02:00
For for background copy go routine to exit
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/kovidgoyal/go-parallel"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -402,6 +403,11 @@ func copy_file_and_close(ctx context.Context, src *os.File, dest *os.File) (err
|
|||||||
dest.Close()
|
dest.Close()
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
err_chan <- parallel.Format_stacktrace_on_panic(r, 1)
|
||||||
|
}
|
||||||
|
}()
|
||||||
// this go routine will automatically exit when src/dest are closed
|
// this go routine will automatically exit when src/dest are closed
|
||||||
// even if copying is not complete. io.Copy() automatically use
|
// even if copying is not complete. io.Copy() automatically use
|
||||||
// sendfile() or similar mechanisms for efficiency.
|
// sendfile() or similar mechanisms for efficiency.
|
||||||
@@ -411,6 +417,10 @@ func copy_file_and_close(ctx context.Context, src *os.File, dest *os.File) (err
|
|||||||
|
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
// wait for go routine to exit
|
||||||
|
src.Close()
|
||||||
|
dest.Close()
|
||||||
|
<-err_chan
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
case err := <-err_chan:
|
case err := <-err_chan:
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user