Forked from RaviH/SwitchIfEmptyObservableExample.groovy
Created
August 31, 2017 16:00
-
-
Save miroslavign/4ab1dbc703f25bf4509880e970bed0ab to your computer and use it in GitHub Desktop.
Switch If Empty 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" | |
} | |
}).switchIfEmpty(defaultMethod()) | |
println(resultObs.toBlocking().first()) | |
} | |
static Observable<String> defaultMethod() { | |
println "defaultMethod" | |
return Observable.just("default") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment