Skip to content

Instantly share code, notes, and snippets.

@chooblarin
Last active May 5, 2017 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chooblarin/a041328422870581c616f32717d80393 to your computer and use it in GitHub Desktop.
Save chooblarin/a041328422870581c616f32717d80393 to your computer and use it in GitHub Desktop.
Playing with RxSwift Scheduler
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