From 75cd8a63fd77b953260b7219c14f3f755f5327e2 Mon Sep 17 00:00:00 2001 From: Dariusz Rybicki <dariusz@elixxir.io> Date: Fri, 29 Jul 2022 15:14:26 +0100 Subject: [PATCH] Add NewBroadcastChannel functor --- .../Functors/NewBroadcastChannel.swift | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Sources/ElixxirDAppsSDK/Functors/NewBroadcastChannel.swift diff --git a/Sources/ElixxirDAppsSDK/Functors/NewBroadcastChannel.swift b/Sources/ElixxirDAppsSDK/Functors/NewBroadcastChannel.swift new file mode 100644 index 00000000..11e519fa --- /dev/null +++ b/Sources/ElixxirDAppsSDK/Functors/NewBroadcastChannel.swift @@ -0,0 +1,37 @@ +import Bindings +import XCTestDynamicOverlay + +public struct NewBroadcastChannel { + public var run: (Int, ChannelDef) throws -> Channel + + public func callAsFunction( + cmixId: Int, + channelDef: ChannelDef + ) throws -> Channel { + try run(cmixId, channelDef) + } +} + +extension NewBroadcastChannel { + public static let live = NewBroadcastChannel { cmixId, channelDef in + var error: NSError? + let bindingsChannel = BindingsNewBroadcastChannel( + cmixId, + try channelDef.encode(), + &error + ) + if let error = error { + throw error + } + guard let bindingsChannel = bindingsChannel else { + fatalError("BindingsNewBroadcastChannel returned `nil` without providing error") + } + return .live(bindingsChannel) + } +} + +extension NewBroadcastChannel { + public static let unimplemented = NewBroadcastChannel( + run: XCTUnimplemented("\(Self.self)") + ) +} -- GitLab