mirror of
https://github.com/rclone/rclone
synced 2024-12-27 19:43:48 +01:00
atexit: implement OnError for cancelling multpart uploads
This commit is contained in:
parent
fcc2db8093
commit
54fda3422e
@ -77,3 +77,23 @@ func Run() {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// OnError registers fn with atexit and returns a function which
|
||||
// runs fn() if *perr != nil and deregisters fn
|
||||
//
|
||||
// It should be used in a defer statement normally so
|
||||
//
|
||||
// defer OnError(&err, cancelFunc)()
|
||||
//
|
||||
// So cancelFunc will be run if the function exits with an error or
|
||||
// at exit.
|
||||
func OnError(perr *error, fn func()) func() {
|
||||
handle := Register(fn)
|
||||
return func() {
|
||||
defer Unregister(handle)
|
||||
if *perr != nil {
|
||||
fn()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user