From 1aed887059f7b6c5a2297a1eba77a1a653a0bddd Mon Sep 17 00:00:00 2001 From: Pat Brown Date: Sun, 3 Nov 2024 12:18:08 +1100 Subject: [PATCH] Avoid extra lock for subscriptions --- .../ComposableArchitecture/Internal/CurrentValueRelay.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sources/ComposableArchitecture/Internal/CurrentValueRelay.swift b/Sources/ComposableArchitecture/Internal/CurrentValueRelay.swift index 6f8a9eb61c4d..bb09e396e08b 100644 --- a/Sources/ComposableArchitecture/Internal/CurrentValueRelay.swift +++ b/Sources/ComposableArchitecture/Internal/CurrentValueRelay.swift @@ -33,10 +33,11 @@ final class CurrentValueRelay: Publisher { } func send(_ value: Output) { - self.lock.sync { + let subscriptions = self.lock.sync { self.currentValue = value + return self.subscriptions } - for subscription in self.lock.sync({ self.subscriptions }) { + for subscription in subscriptions { subscription.receive(value) } }