Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save miroslavign/4ab1dbc703f25bf4509880e970bed0ab to your computer and use it in GitHub Desktop.
Save miroslavign/4ab1dbc703f25bf4509880e970bed0ab to your computer and use it in GitHub Desktop.
Switch If Empty Observable example
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