mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-06-15 09:03:20 +02:00
Delayed deletion
This commit is contained in:
parent
9c082a8331
commit
954d919361
14 changed files with 280 additions and 131 deletions
util
12
util/util.go
12
util/util.go
|
@ -324,3 +324,15 @@ func UnmarshalJSONWithLimit[T any](r io.ReadCloser, limit int) (*T, error) {
|
|||
}
|
||||
return &obj, nil
|
||||
}
|
||||
|
||||
// Retry executes function f until if succeeds, and then returns t. If f fails, it sleeps
|
||||
// and tries again. The sleep durations are passed as the after params.
|
||||
func Retry[T any](f func() (*T, error), after ...time.Duration) (t *T, err error) {
|
||||
for _, delay := range after {
|
||||
if t, err = f(); err == nil {
|
||||
return t, nil
|
||||
}
|
||||
time.Sleep(delay)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue