android - Trying to Rxify an already asynchronous flow -


i have situation before me wherein have asynchronous system in place , i'm looking convert rx streams. flow part of 3rd party library without me having source modify. i'm looking create rx wrapper around it.

can't share exact code here give brief idea, have created singleton class acts manager flow. in singleton class, have initialised object of class present in 3rd party library. during initialisation of object, have pass reference of callback class in constructor , callback library provides responses method calls asynchronously.

callback callback = new callback() {
public void onresponse(message message) {
// perform action
}
};
someclassinsdk clazz = new someclassinsdk(callback);

what i'm looking here convert async system rx streams , can't seem figure out how begin me being newbie rxjava2.

i tried replicate code of retrofit rxjava2 adapter code has new callback object initialised every observable can't have in code.

any appreciated.

you can use observable.fromcallable() docs link. wrap async callback method , returns observable.

you can use single & maybe. docs more details:

following example of using single convert imperative programming paradigm reactive.

public single<string> mymethod() {         return single.create(new single.onsubscribe<string>() {             @override             public void call(final singlesubscriber<? super string> singlesubscriber) {                  myasyncmethod(new callback() {                     public void success(string data) {                         singlesubscriber.onsuccess(data); // call upon success                                             }                      public void failure(string err) {                         singlesubscriber.onerror(err);                                             }                 })             }         });     } 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -