Skip to content

Instantly share code, notes, and snippets.

@pangers
Last active May 21, 2016 04:37
Show Gist options
  • Save pangers/ae21683f5e9a8ab7ae91 to your computer and use it in GitHub Desktop.
Save pangers/ae21683f5e9a8ab7ae91 to your computer and use it in GitHub Desktop.
_ = Observable.just("hello")
.map {
return $0.characters.count //On main thread
}
.map {
return $0 + 5 // On main thread
}
.map {
return $0 + 10 // On main thread
}
.subscribeNext { //Observable subscribed to on main thread
print($0)
}
//Main thread at point of observable creation
_ = Observable.just("hello")
.map {
return $0.characters.count //On user interactive dispatch queue
}
.map {
return $0 + 5 //On user interactive dispatch queue
}
.map {
return $0 + 10 //On user interactive dispatch queue
}
.subscribeOn(ConcurrentDispatchQueueScheduler(globalConcurrentQueueQOS: .UserInteractive)) // User Interactive dispatch queue passed to subscribe on operator
.subscribeNext { //Observable subscribed to on main thread
print($0) //Printed on user initiated dispatch queue
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment