mirror of
https://github.com/home-assistant/iOS.git
synced 2026-02-17 22:02:08 -06:00
Adds code coverage reports to pull requests. Enabling code coverage gathering appears to be about a 25% increase in build time, unfortunately, so just enabling it for the App/Shared targets and doing it in a separate scheme so it doesn't impact local build times.
25 lines
733 B
Swift
25 lines
733 B
Swift
import Foundation
|
|
import PromiseKit
|
|
|
|
// https://github.com/mxcl/PromiseKit/blob/master/Documentation/CommonPatterns.md
|
|
func attemptNetworking<T>(
|
|
maximumRetryCount: Int = 3,
|
|
delayBeforeRetry: DispatchTimeInterval = .seconds(2),
|
|
_ body: @escaping () -> Promise<T>
|
|
) -> Promise<T> {
|
|
var attempts = 0
|
|
func attempt() -> Promise<T> {
|
|
attempts += 1
|
|
return body().recover { error -> Promise<T> in
|
|
guard attempts < maximumRetryCount, error is URLError else { throw error }
|
|
|
|
if Current.isRunningTests {
|
|
return attempt()
|
|
} else {
|
|
return after(delayBeforeRetry).then(on: .main, attempt)
|
|
}
|
|
}
|
|
}
|
|
return attempt()
|
|
}
|