Last active
April 11, 2018 06:49
-
-
Save rajajawahar/ae9a3f20db67672cd3e6ce059bbb5c6b 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
class ViewController: UIViewController { | |
let disposeBag = DisposeBag() | |
var prefetchMaster : ConnectableObservable<Int>! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
prefetchMaster = Observable.interval(1, scheduler: MainScheduler.instance).publish() | |
print("Published") | |
let subscriber = prefetchMaster.subscribe{ | |
print("Next: \($0)") | |
} | |
prefetchMaster.connect() | |
print("Connected") | |
DispatchQueue.main.asyncAfter(deadline: .now() + 2) { | |
print("Disposing after 3 seconds") | |
subscriber.dispose() | |
} | |
DispatchQueue.main.asyncAfter(deadline: .now() + 6) { | |
print("Subscribing again after 6 seconds") | |
self.prefetchMaster.subscribe { | |
print("Next: \($0)") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment