Skip to content

Instantly share code, notes, and snippets.

@pokk
Last active August 21, 2017 04:07
Show Gist options
  • Save pokk/e42ac20a91c0c2578f8627b9a4044b57 to your computer and use it in GitHub Desktop.
Save pokk/e42ac20a91c0c2578f8627b9a4044b57 to your computer and use it in GitHub Desktop.
Introduction Instead of callback function hell, we will use an elegant way `RxJava2` to achieve it. How to do We can use `subject` or `processor`(with backpressure) to omit a callback function. Otherwise, if we just use an `observable`, it cant invoke `onNext` somewhere. Due to an `observable` will create so many new objects, using them is bette…
// A class
fun caller() {
// here we will set callback function.
callbackProcessor.subscriby {
// Here I can get `5566`, and do somthing.
}
}
// B class
fun callee() {
val callbackProcessor = PublishProcessor.create<Int>()
// This is callback place.
fun onXXFun() {
callbackProcessor.onNext(5566)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment