Skip to content
Snippets Groups Projects

Fix sleep interval in MessengerWaitForNodes

Merged Dariusz Rybicki requested to merge fix/messener-wait-for-nodes-sleep into development
3 files
+ 13
12
Compare changes
  • Side-by-side
  • Inline
Files
3
 
import Foundation
import XXClient
import XXClient
import XCTestDynamicOverlay
import XCTestDynamicOverlay
@@ -9,21 +10,21 @@ public struct MessengerWaitForNodes {
@@ -9,21 +10,21 @@ public struct MessengerWaitForNodes {
case timeout
case timeout
}
}
public var run: (Double, Int, Int, @escaping Progress) throws -> Void
public var run: (Double, TimeInterval, Int, @escaping Progress) throws -> Void
public func callAsFunction(
public func callAsFunction(
targetRatio: Double = 0.8,
targetRatio: Double = 0.8,
sleepMS: Int = 1_000,
sleepInterval: TimeInterval = 1,
retries: Int = 10,
retries: Int = 10,
onProgress: @escaping Progress = { _ in }
onProgress: @escaping Progress = { _ in }
) throws {
) throws {
try run(targetRatio, sleepMS, retries, onProgress)
try run(targetRatio, sleepInterval, retries, onProgress)
}
}
}
}
extension MessengerWaitForNodes {
extension MessengerWaitForNodes {
public static func live(_ env: MessengerEnvironment) -> MessengerWaitForNodes {
public static func live(_ env: MessengerEnvironment) -> MessengerWaitForNodes {
MessengerWaitForNodes { targetRatio, sleepMS, retries, onProgress in
MessengerWaitForNodes { targetRatio, sleepInterval, retries, onProgress in
guard let cMix = env.cMix() else {
guard let cMix = env.cMix() else {
throw Error.notLoaded
throw Error.notLoaded
}
}
@@ -33,7 +34,7 @@ extension MessengerWaitForNodes {
@@ -33,7 +34,7 @@ extension MessengerWaitForNodes {
onProgress(report)
onProgress(report)
while report.ratio < targetRatio && retries > 0 {
while report.ratio < targetRatio && retries > 0 {
env.sleep(sleepMS)
env.sleep(sleepInterval)
report = try cMix.getNodeRegistrationStatus()
report = try cMix.getNodeRegistrationStatus()
retries -= 1
retries -= 1
onProgress(report)
onProgress(report)
Loading