1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-02 08:25:02 -04:00

* added retry { ... } construct

This commit is contained in:
Reinhard Pointner 2012-10-28 15:01:31 +00:00
parent a7822901f8
commit 99a2013153

View File

@ -359,3 +359,20 @@ def tryQuietly(c) {
return null
}
}
/**
* Retry given closure until it returns successfully (indefinitely by default)
*/
def retry(n = -1, quiet = false, c) {
for(int i = 1; i <= n; i++) {
try {
return c.call()
} catch(Throwable e) {
if (i >= 0 && i >= n) {
throw e
} else if (!quiet) {
_log.warning("retry $i: ${e.class.simpleName}: ${e.message}")
}
}
}
}