Skip to content
Snippets Groups Projects
Commit a44341bb authored by Dariusz Rybicki's avatar Dariusz Rybicki
Browse files

Add NetworkFollower with status and starter

parent 5eeacf4b
No related branches found
No related tags found
1 merge request!2Bindings API wrapper
import Bindings
public struct Client {
public var networkFollower: NetworkFollower
}
extension Client {
public static func live(bindingsClient: BindingsClient) -> Client {
Client()
Client(
networkFollower: .live(bindingsClient: bindingsClient)
)
}
}
#if DEBUG
extension Client {
public static let failing = Client()
public static let failing = Client(
networkFollower: .failing
)
}
#endif
import Bindings
public struct NetworkFollower {
public var status: NetworkFollowerStatusProvider
public var start: NetworkFollowerStarter
}
extension NetworkFollower {
public static func live(bindingsClient: BindingsClient) -> NetworkFollower {
NetworkFollower(
status: .live(bindingsClient: bindingsClient),
start: .live(bindingsClient: bindingsClient)
)
}
}
#if DEBUG
extension NetworkFollower {
public static let failing = NetworkFollower(
status: .failing,
start: .failing
)
}
#endif
import Bindings
public struct NetworkFollowerStarter {
public var start: (_ timeoutMS: Int) throws -> Void
public func callAsFunction(timeoutMS: Int) throws {
try start(timeoutMS)
}
}
extension NetworkFollowerStarter {
public static func live(bindingsClient: BindingsClient) -> NetworkFollowerStarter {
NetworkFollowerStarter { timeoutMS in
try bindingsClient.startNetworkFollower(timeoutMS)
}
}
}
#if DEBUG
extension NetworkFollowerStarter {
public static let failing = NetworkFollowerStarter { _ in
struct NotImplemented: Error {}
throw NotImplemented()
}
}
#endif
public enum NetworkFollowerStatus: Equatable {
case stopped
case starting
case running
case stopping
case unknown(code: Int)
}
extension NetworkFollowerStatus {
public init(rawValue: Int) {
switch rawValue {
case 0: self = .stopped
case 1_000: self = .starting
case 2_000: self = .running
case 3_000: self = .stopping
case let code: self = .unknown(code: code)
}
}
public var rawValue: Int {
switch self {
case .stopped: return 0
case .starting: return 1_000
case .running: return 2_000
case .stopping: return 3_000
case .unknown(let code): return code
}
}
}
import Bindings
public struct NetworkFollowerStatusProvider {
public var status: () -> NetworkFollowerStatus
public func callAsFunction() -> NetworkFollowerStatus {
status()
}
}
extension NetworkFollowerStatusProvider {
public static func live(bindingsClient: BindingsClient) -> NetworkFollowerStatusProvider {
NetworkFollowerStatusProvider {
let rawValue = bindingsClient.networkFollowerStatus()
return NetworkFollowerStatus(rawValue: rawValue)
}
}
}
#if DEBUG
extension NetworkFollowerStatusProvider {
public static let failing = NetworkFollowerStatusProvider {
.unknown(code: -1)
}
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment