mirror of https://github.com/oxen-io/session-ios
Implement retrying
parent
22623815bb
commit
a440a08a04
@ -0,0 +1,10 @@
|
||||
import PromiseKit
|
||||
|
||||
internal extension AnyPromise {
|
||||
|
||||
internal static func from<T : Any>(_ promise: Promise<T>) -> AnyPromise {
|
||||
let result = AnyPromise(promise)
|
||||
result.retainUntilComplete()
|
||||
return result
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
import PromiseKit
|
||||
|
||||
internal extension Promise {
|
||||
|
||||
internal func retryingIfNeeded(maxRetryCount: UInt) -> Promise<T> {
|
||||
var retryCount = 0
|
||||
func retryIfNeeded() -> Promise<T> {
|
||||
return recover { error -> Promise<T> in
|
||||
guard retryCount != maxRetryCount else { throw error }
|
||||
retryCount += 1
|
||||
return retryIfNeeded()
|
||||
}
|
||||
}
|
||||
return retryIfNeeded()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue