diff --git a/Sources/Entwine/Operators/ReplaySubject.swift b/Sources/Entwine/Operators/ReplaySubject.swift index fb90c9d..9cda932 100644 --- a/Sources/Entwine/Operators/ReplaySubject.swift +++ b/Sources/Entwine/Operators/ReplaySubject.swift @@ -35,8 +35,6 @@ public final class ReplaySubject { typealias Sink = AnySubscriber private var subscriptions = [ReplaySubjectSubscription]() - private var subscriberIdentifiers = Set() - private var replayValues: ReplaySubjectValueBuffer private var completion: Subscribers.Completion? @@ -55,32 +53,13 @@ public final class ReplaySubject { extension ReplaySubject: Publisher { public func receive(subscriber: S) where Failure == S.Failure, Output == S.Input { - - guard !subscriberIdentifiers.contains(subscriber.combineIdentifier) else { - subscriber.receive(subscription: Subscriptions.empty) - return - } - let subscriberIdentifier = subscriber.combineIdentifier - let subscription = ReplaySubjectSubscription(sink: AnySubscriber(subscriber)) - - // we use seperate collections for identifiers and subscriptions - // to improve performance of identifier lookups and to keep the - // order in which subscribers are signalled to be in the order that - // they intially subscribed. - - subscriberIdentifiers.insert(subscriberIdentifier) subscriptions.append(subscription) - subscription.cleanupHandler = { [weak self] in - - guard let self = self else { return } - - if let index = self.subscriptions.firstIndex(where: { subscriberIdentifier == $0.subscriberIdentifier }) { - self.subscriberIdentifiers.remove(subscriberIdentifier) - self.subscriptions.remove(at: index) - } + let firstIndex = self?.subscriptions.firstIndex { subscriberIdentifier == $0.subscriberIdentifier } + guard let index = firstIndex else { return } + self?.subscriptions.remove(at: index) } subscriber.receive(subscription: subscription) subscription.replayInputs(replayValues.buffer, completion: completion) diff --git a/Tests/EntwineTests/ReplaySubjectTests.swift b/Tests/EntwineTests/ReplaySubjectTests.swift index 33b44dc..c0eb598 100644 --- a/Tests/EntwineTests/ReplaySubjectTests.swift +++ b/Tests/EntwineTests/ReplaySubjectTests.swift @@ -169,7 +169,6 @@ final class ReplaySubjectTests: XCTestCase { scheduler.schedule(after: 600) { subject.send(0) } scheduler.schedule(after: 700) { subject.send(completion: .finished) } - scheduler.resume() let expected1: TestSequence = [