Skip to content

Instantly share code, notes, and snippets.

@ThanawatMas
Last active December 2, 2018 17:20
Show Gist options
  • Save ThanawatMas/6af6817a5f1c951d0bb4ae09bdd9e3b1 to your computer and use it in GitHub Desktop.
Save ThanawatMas/6af6817a5f1c951d0bb4ae09bdd9e3b1 to your computer and use it in GitHub Desktop.
public class MergeOperation implements RxOperationCase {
@Override
public void runSmoothAtSilk() {
String TAG = "MergeOperation.runSmoothAtSilk";
System.out.println(TAG + " START >>>>>> ");
Observable.merge(UserProfile.mockApi(), LuckyCategory.mockApi(), FortuneQueue.mockApi())
.observeOn(Schedulers.io())
.subscribeOn(Schedulers.io())
.subscribe(new ResourceObserver<Api>() {
@Override
public void onNext(Api api) {
System.out.println(TAG + " onNext: " + api.getApiName());
}
@Override
public void onError(Throwable throwable) {
System.out.println(TAG + " onError: ");
}
@Override
public void onComplete() {
//todo: Logic lucky person here!!
System.out.println(TAG + " onComplete!!!");
}
});
}
@Override
public void runStickWithProblem() {
String TAG = "MergeOperation.runStickWithProblem";
System.out.println(TAG + " START >>>>>> ");
Observable.merge(UserProfile.mockApi(), LuckyCategory.mockFailedApi(), FortuneQueue.mockApi())
.subscribeOn(Schedulers.io())
.subscribe(new ResourceObserver<Api>() {
@Override
public void onNext(Api api) {
System.out.println(TAG + " onNext: " + api.getApiName());
}
@Override
public void onError(Throwable throwable) {
System.out.println(TAG + " onError: " + throwable.getMessage());
}
@Override
public void onComplete() {
//todo: Logic lucky person here!!
System.out.println(TAG + " onComplete!!!");
}
});
}
}
public interface RxOperationCase {
void runSmoothAtSilk();
void runStickWithProblem();
}
public class ZipOperation implements RxOperationCase {
@Override
public void runSmoothAtSilk() {
String TAG = "ZipOperation.runSmoothAtSilk";
System.out.println(TAG + " START >>>>>> ");
Observable.zip(UserProfile.mockApi(), LuckyCategory.mockApi(), FortuneQueue.mockApi(), (api, api2, api3) -> {
//todo: Logic lucky person here!!
System.out.println(TAG + " apply: " + api.getApiName() + ", " + api2.getApiName() + ", " + api3.getApiName());
return "Object that mix data from call!!";
})
.observeOn(Schedulers.newThread())
.subscribeOn(Schedulers.newThread())
.subscribe(new ResourceObserver<Object>() {
@Override
public void onNext(Object result) {
System.out.println(TAG + " onNext: " + result);
}
@Override
public void onError(Throwable throwable) {
System.out.println(TAG + " onError: " + throwable.getMessage());
}
@Override
public void onComplete() {
System.out.println(TAG + " onComplete!!!");
}
});
}
@Override
public void runStickWithProblem() {
String TAG = "ZipOperation.runStickWithProblem";
System.out.println(TAG + " START >>>>>> ");
Observable.zip(UserProfile.mockApi(), LuckyCategory.mockFailedApi(), FortuneQueue.mockApi(), (api, api2, api3) -> {
//todo: Logic lucky person here!!
System.out.println(TAG + " apply: ");
return "Object that mix data from call!!";
})
.observeOn(Schedulers.newThread())
.subscribeOn(Schedulers.newThread())
.subscribe(new ResourceObserver<Object>() {
@Override
public void onNext(Object result) {
System.out.println(TAG + " onNext: " + result);
}
@Override
public void onError(Throwable throwable) {
System.out.println(TAG + " onError: " + throwable.getMessage());
}
@Override
public void onComplete() {
System.out.println(TAG + " onComplete!!!");
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment