import PromiseKit /// Retry the promise constructed in `body` up to `maxRetryCount` times. public func attempt(maxRetryCount: UInt, recoveringOn queue: DispatchQueue, body: @escaping () -> Promise) -> Promise { var retryCount = 0 func attempt() -> Promise { return body().recover(on: queue) { error -> Promise in guard retryCount < maxRetryCount else { throw error } retryCount += 1 return attempt() } } return attempt() }