Created
November 7, 2019 10:28
-
-
Save isaac-weisberg/c5aa678ea63b114e15efde4ea033f085 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func a() { | |
let first = Observables.just(()) | |
let second = Observables.just(()) | |
// will use the super-prime implementation | |
// because both are sync and all sync | |
// schedulers are always equal to each other | |
_ = Observables.combineLatest(first, second) { _, _ in () } | |
} | |
func b() { | |
let first = Observables.just(()) | |
.observeOn(MainScheduler()) | |
let second = Observables.just(()) | |
.observeOn(MainScheduler()) | |
// will use the super-prime implementation | |
// because both schedulers are equal | |
// because their dispatch queues are referrentially equal | |
_ = Observables.combineLatest(first, second) { _, _ in () } | |
} | |
func c() { | |
let first = Observables.just(()) | |
.observeOn(SerialDispatchQScheduler()) | |
let second = Observables.just(()) | |
.observeOn(SerialDispatchQScheduler()) | |
// won't use the super-prime implementation | |
// because although schedulers are | |
// type equivalent, on runtime their queues | |
// are will be different and synchronization | |
// will be required | |
_ = Observables.combineLatest(first, second) { _, _ in () } | |
} | |
func c2() { | |
let queue = DispatchQueue(label: "", attributes: .concurrent) | |
let first = Observables.just(()) | |
.observeOn(DispatchQueueScheduler(queue: queue)) | |
let second = Observables.just(()) | |
.observeOn(DispatchQueueScheduler(queue: queue)) | |
// won't use the super-prime implementation. | |
// Although they are type equivalent | |
// and they will be equal dynamically, | |
// the dispatch queue that they use | |
// doesn't synchronize the emissions | |
_ = Observables.combineLatest(first, second) { _, _ in () } | |
} | |
func d() { | |
let scheduler = SerialDispatchQScheduler() | |
let first = Observables.just(()) | |
.observeOn(scheduler) | |
let second = Observables.just(()) | |
.observeOn(scheduler) | |
// will use the super-prime implementation | |
// because of static and dynamic equality | |
_ = Observables.combineLatest(first, second) { _, _ in () } | |
} | |
func e() { | |
let scheduler = SerialDispatchQScheduler() | |
let first = Observables.just(()) | |
.observeOn(scheduler) | |
let second = Observables.just(()) | |
.observeOn(scheduler) | |
// will use the super-prime implementation | |
// because the equality is proven statically | |
// and dynamically | |
_ = Observables.combineLatest(first, second) { _, _ in () } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment