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

Add RestlikeCallback wrapper

parent 91afb0d2
No related branches found
No related tags found
2 merge requests!102Release 1.0.0,!18Update Bindings
import Bindings
import XCTestDynamicOverlay
public struct RestlikeCallback {
public init(handle: @escaping (Result<RestlikeMessage, NSError>) -> Void) {
self.handle = handle
}
public var handle: (Result<RestlikeMessage, NSError>) -> Void
}
extension RestlikeCallback {
public static let unimplemented = RestlikeCallback(
handle: XCTUnimplemented("\(Self.self)")
)
}
extension RestlikeCallback {
func makeBindingsRestlikeCallback() -> BindingsRestlikeCallbackProtocol {
class Callback: NSObject, BindingsRestlikeCallbackProtocol {
init(_ callback: RestlikeCallback) {
self.callback = callback
}
let callback: RestlikeCallback
func callback(_ p0: Data?, p1: Error?) {
if let error = p1 {
callback.handle(.failure(error as NSError))
} else if let messageData = p0 {
do {
callback.handle(.success(try RestlikeMessage.decode(messageData)))
} catch {
callback.handle(.failure(error as NSError))
}
} else {
fatalError("BindingsRestlikeCallback received `nil` message and `nil` error")
}
}
}
return Callback(self)
}
}
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