Skip to content

Commit

Permalink
Blocks RefCount from connecting in case source sequence immediatelly …
Browse files Browse the repository at this point in the history
…terminated. #1242 #1111
  • Loading branch information
kzaher committed May 27, 2017
1 parent f831ec3 commit eac3337
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 27 deletions.
3 changes: 3 additions & 0 deletions RxSwift/Observables/Multicast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ final fileprivate class RefCountSink<CO: ConnectableObservableType, O: ObserverT

func run() -> Disposable {
let subscription = _parent._source.subscribe(self)
if self.disposed {
return Disposables.create()
}

_parent._lock.lock(); defer { _parent._lock.unlock() } // {
if _parent._count == 0 {
Expand Down
31 changes: 4 additions & 27 deletions Tests/RxSwiftTests/Observable+ShareReplay1Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,7 @@ extension ObservableShareReplay1Test {
])

// unoptimized version of replay subject will make a subscription and kill it immediately
XCTAssertEqual(xs.subscriptions[0], Subscription(335, 365))

switch version {
case .composition:
XCTAssertTrue(xs.subscriptions.count == 2 && xs.subscriptions[1] == Subscription(440, 440))
case .optimized:
XCTAssertTrue(xs.subscriptions.count == 1)
}
XCTAssertEqual(xs.subscriptions, [Subscription(335, 365)])
}
}

Expand Down Expand Up @@ -275,15 +268,7 @@ extension ObservableShareReplay1Test {
completed(365)
])

XCTAssertEqual(xs.subscriptions[0], Subscription(335, 365))

// unoptimized version of replay subject will make a subscription and kill it immediately
switch version {
case .composition:
XCTAssertTrue(xs.subscriptions.count == 2 && xs.subscriptions[1] == Subscription(440, 440))
case .optimized:
XCTAssertTrue(xs.subscriptions.count == 1)
}
XCTAssertEqual(xs.subscriptions, [Subscription(335, 365)])
}
}

Expand Down Expand Up @@ -401,18 +386,10 @@ extension ObservableShareReplay1Test {
completed(365)
])

XCTAssertEqual(xs.subscriptions[0], Subscription(335, 365))

// unoptimized version of replay subject will make a subscription and kill it immediately
switch version {
case .composition:
XCTAssertTrue(xs.subscriptions.count == 2 && xs.subscriptions[1] == Subscription(440, 440))
case .optimized:
XCTAssertTrue(xs.subscriptions.count == 1)
}
XCTAssertEqual(xs.subscriptions, [Subscription(335, 365)])
}
}

#if TRACE_RESOURCES
func testShareReplayReleasesResourcesOnComplete() {
_ = Observable<Int>.just(1).shareReplay(1).subscribe()
Expand Down

0 comments on commit eac3337

Please sign in to comment.