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

Add SingleUseCallback

parent 125335d9
No related branches found
No related tags found
2 merge requests!102Release 1.0.0,!18Update Bindings
import Bindings
import XCTestDynamicOverlay
public struct SingleUseCallback {
public init(handle: @escaping (Result<SingleUseCallbackReport, NSError>) -> Void) {
self.handle = handle
}
public var handle: (Result<SingleUseCallbackReport, NSError>) -> Void
}
extension SingleUseCallback {
public static let unimplemented = SingleUseCallback(
handle: XCTUnimplemented("\(Self.self)")
)
}
extension SingleUseCallback {
func makeBindingsSingleUseCallback() -> BindingsSingleUseCallbackProtocol {
class CallbackObject: NSObject, BindingsSingleUseCallbackProtocol {
init(_ callback: SingleUseCallback) {
self.callback = callback
}
let callback: SingleUseCallback
func callback(_ callbackReport: Data?, err: Error?) {
if let error = err {
callback.handle(.failure(error as NSError))
} else if let callbackReport = callbackReport {
do {
callback.handle(.success(try SingleUseCallbackReport.decode(callbackReport)))
} catch {
callback.handle(.failure(error as NSError))
}
} else {
fatalError("BindingsSingleUseCallback received `nil` callbackReport and `nil` error")
}
}
}
return CallbackObject(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