Last active
August 21, 2017 04:07
-
-
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…
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
// 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