diff --git a/Sources/ElixxirDAppsSDK/Functors/NewBroadcastChannel.swift b/Sources/ElixxirDAppsSDK/Functors/NewBroadcastChannel.swift new file mode 100644 index 0000000000000000000000000000000000000000..11e519fa41f0cc38d067e5d494c0b8dd911bb279 --- /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)") + ) +}