Last active
May 5, 2017 04:16
-
-
Save chooblarin/a041328422870581c616f32717d80393 to your computer and use it in GitHub Desktop.
Playing with RxSwift Scheduler
This file contains hidden or 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
import UIKit | |
import RxSandbox | |
import RxSwift | |
import PlaygroundSupport | |
func which() -> String { | |
return Thread.isMainThread ? "main" : "background" | |
} | |
let disposeBag = DisposeBag() | |
let observable = Observable<String>.create { observer -> Disposable in | |
Thread.sleep(forTimeInterval: 5) | |
observer.onNext("YO!😎 from \(which()).") | |
observer.onCompleted() | |
return Disposables.create() | |
} | |
observable | |
.subscribeOn(ConcurrentDispatchQueueScheduler(qos: .default)) | |
.observeOn(MainScheduler.instance) | |
.subscribe(onNext: { (message: String) in | |
print("\(message) (Here is \(which()))") | |
}) | |
.disposed(by: disposeBag) | |
PlaygroundPage.current.liveView = UIView() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment