This commit is contained in:
Михаил Капелько
2023-12-16 11:22:56 +03:00
parent 5d9122cdba
commit a77e1c82b4
4 changed files with 29 additions and 23 deletions

View File

@@ -85,9 +85,9 @@ public extension Bus {
public extension Bus {
static func processSync<Src, Dst>(
_ subscriptions: inout Set<AnyCancellable>,
_ handler: @escaping ((Src) -> Dst?),
_ keyIn: String,
_ keyOut: String,
_ handler: @escaping ((Src) -> Dst?)
_ keyOut: String
) {
Service.singleton.broadcaster
.compactMap {
@@ -102,4 +102,23 @@ public extension Bus {
.sink { vOut in Service.singleton.send(keyOut, vOut) }
.store(in: &subscriptions)
}
static func processSyncG<Src, Dst>(
_ handler: @escaping ((Src) -> Dst?),
_ keyIn: String,
_ keyOut: String
) {
Service.singleton.broadcaster
.compactMap {
guard
$0.key == keyIn,
let vIn = $0.value as? Src
else {
return nil
}
return handler(vIn)
}
.sink { vOut in Service.singleton.send(keyOut, vOut) }
.store(in: &Service.singleton.subscriptions)
}
}