Skip to content

Commit

Permalink
Fixed potential race condition in AsyncImageView due to the double su…
Browse files Browse the repository at this point in the history
…bscription

Fixes #13.
  • Loading branch information
NachoSoto committed Nov 25, 2015
1 parent 13bdd3d commit 3981351
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions AsyncImageView/AsyncImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,12 @@ public final class AsyncImageView<

self.backgroundColor = nil

let requestChanges = self.requestsSignal.skipRepeats()
let uiScheduler = UIScheduler()

requestChanges
self.requestsSignal
.skipRepeats()
.observeOn(uiScheduler)
.observeNext { [weak self] _ in self?.resetImage() }

requestChanges
.on(next: { [weak self] _ in self?.resetImage() })
.observeOn(self.imageCreationScheduler)
.flatMap(.Latest, transform: imageProvider.getImageForData)
.observeOn(uiScheduler)
Expand Down Expand Up @@ -120,3 +118,13 @@ public final class AsyncImageView<
// MARK: - Constants

private let fadeAnimationDuration: NSTimeInterval = 0.4

private extension SignalType {
// TODO: remove once https://github.com/ReactiveCocoa/ReactiveCocoa/pull/2572 is merged.
func on(next next: (Value) -> ()) -> Signal<Value, Error> {
return self.map {
next($0)
return $0
}
}
}

0 comments on commit 3981351

Please sign in to comment.