mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
Caption support (#2462)
Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
57
vendor/github.com/asticode/go-astikit/defer.go
generated
vendored
Normal file
57
vendor/github.com/asticode/go-astikit/defer.go
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
package astikit
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// CloseFunc is a method that closes something
|
||||
type CloseFunc func() error
|
||||
|
||||
// Closer is an object that can close several things
|
||||
type Closer struct {
|
||||
fs []CloseFunc
|
||||
m *sync.Mutex
|
||||
}
|
||||
|
||||
// NewCloser creates a new closer
|
||||
func NewCloser() *Closer {
|
||||
return &Closer{
|
||||
m: &sync.Mutex{},
|
||||
}
|
||||
}
|
||||
|
||||
// Close implements the io.Closer interface
|
||||
func (c *Closer) Close() error {
|
||||
// Lock
|
||||
c.m.Lock()
|
||||
defer c.m.Unlock()
|
||||
|
||||
// Loop through closers
|
||||
err := NewErrors()
|
||||
for _, f := range c.fs {
|
||||
err.Add(f())
|
||||
}
|
||||
|
||||
// Reset closers
|
||||
c.fs = []CloseFunc{}
|
||||
|
||||
// Return
|
||||
if err.IsNil() {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// Add adds a close func at the beginning of the list
|
||||
func (c *Closer) Add(f CloseFunc) {
|
||||
c.m.Lock()
|
||||
defer c.m.Unlock()
|
||||
c.fs = append([]CloseFunc{f}, c.fs...)
|
||||
}
|
||||
|
||||
// NewChild creates a new child closer
|
||||
func (c *Closer) NewChild() (child *Closer) {
|
||||
child = NewCloser()
|
||||
c.Add(child.Close)
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user