From ea661935b5c0db155298d625cf3d60725da81ec6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Wed, 27 Dec 2023 13:06:05 +0300 Subject: [PATCH] d --- src/Bus.Aux.swift | 6 +++--- src/Bus.Processor.swift | 11 ++++++++++- src/Bus.swift | 6 +++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Bus.Aux.swift b/src/Bus.Aux.swift index 45cf523..9284e1d 100644 --- a/src/Bus.Aux.swift +++ b/src/Bus.Aux.swift @@ -14,13 +14,13 @@ extension Bus { } /// Обрабатываем. - static func processKeyValue( + static func processKeysValue( _ v: (key: String, value: Any), - _ keyIn: String, + _ keysIn: Set, _ handler: @escaping ((Src) -> Dst?) ) -> Dst? { guard - v.key == keyIn, + keysIn.contains(v.key), let vIn = v.value as? Src else { return nil diff --git a/src/Bus.Processor.swift b/src/Bus.Processor.swift index edf967e..be3fd14 100644 --- a/src/Bus.Processor.swift +++ b/src/Bus.Processor.swift @@ -10,7 +10,16 @@ public extension Bus { _ handler: @escaping ((Src) -> Dst?), opt: [Option] = [] ) { - Bus.process(keyIn, keyOut, handler, opt: opt, sub: &subscriptions) + Bus.process([keyIn], keyOut, handler, opt: opt, sub: &subscriptions) + } + + public init( + _ keysIn: Set, + _ keyOut: String, + _ handler: @escaping ((Src) -> Dst?), + opt: [Option] = [] + ) { + Bus.process(keysIn, keyOut, handler, opt: opt, sub: &subscriptions) } } } diff --git a/src/Bus.swift b/src/Bus.swift index 6f9e162..5eef129 100644 --- a/src/Bus.swift +++ b/src/Bus.swift @@ -96,7 +96,7 @@ public extension Bus { public extension Bus { static func process( - _ keyIn: String, + _ keysIn: Set, _ keyOut: String, _ handler: @escaping ((Src) -> Dst?), opt: [Option] = [], @@ -108,7 +108,7 @@ public extension Bus { // Async. if isAsync { subscription = Service.singleton.events - .compactMap { processKeyValue($0, keyIn, handler) } + .compactMap { processKeysValue($0, keysIn, handler) } .receive(on: DispatchQueue.main) .sink { vOut in Service.singleton.send(keyOut, vOut) } } @@ -116,7 +116,7 @@ public extension Bus { // Sync. if !isAsync { subscription = Service.singleton.events - .compactMap { processKeyValue($0, keyIn, handler) } + .compactMap { processKeysValue($0, keysIn, handler) } .sink { vOut in Service.singleton.send(keyOut, vOut) } }