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

Add ConnectionCloser

parent 75de26d6
No related branches found
No related tags found
Loading
...@@ -5,6 +5,7 @@ public struct Connection { ...@@ -5,6 +5,7 @@ public struct Connection {
public var getPartner: () -> Data public var getPartner: () -> Data
public var send: MessageSender public var send: MessageSender
public var listen: MessageListener public var listen: MessageListener
public var close: ConnectionCloser
} }
extension Connection { extension Connection {
...@@ -20,7 +21,8 @@ extension Connection { ...@@ -20,7 +21,8 @@ extension Connection {
return data return data
}, },
send: .live(bindingsConnection: bindingsConnection), send: .live(bindingsConnection: bindingsConnection),
listen: .live(bindingsConnection: bindingsConnection) listen: .live(bindingsConnection: bindingsConnection),
close: .live(bindingsConnection: bindingsConnection)
) )
} }
...@@ -36,7 +38,8 @@ extension Connection { ...@@ -36,7 +38,8 @@ extension Connection {
return data return data
}, },
send: .live(bindingsAuthenticatedConnection: bindingsAuthenticatedConnection), send: .live(bindingsAuthenticatedConnection: bindingsAuthenticatedConnection),
listen: .live(bindingsAuthenticatedConnection: bindingsAuthenticatedConnection) listen: .live(bindingsAuthenticatedConnection: bindingsAuthenticatedConnection),
close: .live(bindingsAuthenticatedConnection: bindingsAuthenticatedConnection)
) )
} }
} }
...@@ -47,7 +50,8 @@ extension Connection { ...@@ -47,7 +50,8 @@ extension Connection {
isAuthenticated: { fatalError("Not implemented") }, isAuthenticated: { fatalError("Not implemented") },
getPartner: { fatalError("Not implemented") }, getPartner: { fatalError("Not implemented") },
send: .failing, send: .failing,
listen: .failing listen: .failing,
close: .failing
) )
} }
#endif #endif
import Bindings
public struct ConnectionCloser {
public var close: () -> Void
public func callAsFunction() {
close()
}
}
extension ConnectionCloser {
public static func live(
bindingsConnection: BindingsConnection
) -> ConnectionCloser {
ConnectionCloser(close: bindingsConnection.close)
}
public static func live(
bindingsAuthenticatedConnection: BindingsAuthenticatedConnection
) -> ConnectionCloser {
ConnectionCloser(close: bindingsAuthenticatedConnection.close)
}
}
#if DEBUG
extension ConnectionCloser {
public static let failing = ConnectionCloser {
fatalError("Not implemented")
}
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment