Created
January 14, 2016 17:09
-
-
Save RaviH/5d9d7483e983afbc14df to your computer and use it in GitHub Desktop.
Example of defaultIfEmpty Observable example.
This file contains 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
package com.charter.aesd.activationlogin.edge.service | |
import rx.Observable | |
import rx.functions.Func1 | |
import rx.functions.Func3 | |
/** | |
* Created by rhasija on 1/14/16. | |
*/ | |
class ObsTest { | |
public static void main(String[] args) { | |
def foo1 = Observable.just("123") | |
def foo2 = Observable.just("456") | |
def foo3 = Observable.error(new RuntimeException("edfrf")) | |
def resultObs = Observable.zip(foo1, foo2, foo3, new Func3() { | |
@Override | |
Object call(Object o, Object o2, Object o3) { | |
return "Inside Observable" | |
} | |
}).onErrorReturn(new Func1() { | |
@Override | |
Object call(Object o) { | |
println "Error got called" | |
return "error" | |
} | |
}).defaultIfEmpty(defaultMethod()) | |
println(resultObs.toBlocking().first()) | |
} | |
static String defaultMethod() { | |
println "defaultMethod" | |
return "default" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment