fix(uploader, files/handlers): fix incorrect unlock, catch and check error after calling api (#26)
* fix(uploader, files/handlers): fix incorrect unlock, catch and check after calling api * fix(uploader): fix uploader test
This commit is contained in:
parent
64493ec76a
commit
cb26003b99
3 changed files with 32 additions and 11 deletions
|
@ -76,13 +76,16 @@ func (h *FileHandlers) NewAutoLocker(c *gin.Context, key string) *AutoLocker {
|
|||
func (lk *AutoLocker) Exec(handler func()) {
|
||||
var err error
|
||||
kv := lk.h.deps.KV()
|
||||
locked := false
|
||||
|
||||
defer func() {
|
||||
if p := recover(); p != nil {
|
||||
fmt.Println(p)
|
||||
}
|
||||
if err = kv.Unlock(lk.key); err != nil {
|
||||
fmt.Println(err)
|
||||
if locked {
|
||||
if err = kv.Unlock(lk.key); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -91,6 +94,7 @@ func (lk *AutoLocker) Exec(handler func()) {
|
|||
return
|
||||
}
|
||||
|
||||
locked = true
|
||||
handler()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue