Skip to content

Instantly share code, notes, and snippets.

@Ravi61
Created August 18, 2019 12:07
Show Gist options
  • Save Ravi61/17462d802c3fdd2aa3813ed4391447dc to your computer and use it in GitHub Desktop.
Save Ravi61/17462d802c3fdd2aa3813ed4391447dc to your computer and use it in GitHub Desktop.
Zipping two Observables to explain Backpressure
let aScheduler = SerialDispatchQueueScheduler(internalSerialQueueName: "backgroundQueue1")
let A = Observable.repeatElement("A", scheduler: aScheduler).throttle(.seconds(1), scheduler: aScheduler)
let bScheduler = SerialDispatchQueueScheduler(internalSerialQueueName: "backgroundQueue2")
let B = Observable.repeatElement("B", scheduler: bScheduler).throttle(.seconds(2), scheduler: bScheduler)
_ = Observable.zip(A, B)
.subscribe(onNext: { (valueA, valueB) in
print("\(valueA) \(valueB)")
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment