mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Fix various generate issues (#1322)
Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
22
pkg/utils/time.go
Normal file
22
pkg/utils/time.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package utils
|
||||
|
||||
import "time"
|
||||
|
||||
// Timeout executes the provided todo function, and waits for it to return. If
|
||||
// the function does not return before the waitTime duration is elapsed, then
|
||||
// onTimeout is executed, passing a channel that will be closed when the
|
||||
// function returns.
|
||||
func Timeout(todo func(), waitTime time.Duration, onTimeout func(done chan struct{})) {
|
||||
done := make(chan struct{})
|
||||
|
||||
go func() {
|
||||
todo()
|
||||
close(done)
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-done: // on time, just exit
|
||||
case <-time.After(waitTime):
|
||||
onTimeout(done)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user