mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
14 lines
507 B
Swift
14 lines
507 B
Swift
import PromiseKit
|
|
|
|
/// Retry the promise constructed in `body` up to `maxRetryCount` times.
|
|
public func attempt<T>(maxRetryCount: UInt, recoveringOn queue: DispatchQueue, body: @escaping () -> Promise<T>) -> Promise<T> {
|
|
var retryCount = 0
|
|
func attempt() -> Promise<T> {
|
|
return body().recover(on: queue) { error -> Promise<T> in
|
|
guard retryCount < maxRetryCount else { throw error }
|
|
retryCount += 1
|
|
return attempt()
|
|
}
|
|
}
|
|
return attempt()
|
|
}
|