Commit bcfb862d authored by Yusuke Iwaki's avatar Yusuke Iwaki

remove RxHelper#lazy. Use Single#defer instead.

parent bf3519a5
...@@ -2,8 +2,6 @@ package chat.rocket.android.helper; ...@@ -2,8 +2,6 @@ package chat.rocket.android.helper;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import rx.Observable; import rx.Observable;
import rx.Single;
import rx.functions.Func0;
import rx.functions.Func1; import rx.functions.Func1;
/** /**
...@@ -16,8 +14,4 @@ public class RxHelper { ...@@ -16,8 +14,4 @@ public class RxHelper {
.zipWith(Observable.range(0, maxRetryCount), (error, retryCount) -> retryCount) .zipWith(Observable.range(0, maxRetryCount), (error, retryCount) -> retryCount)
.flatMap(retryCount -> Observable.timer(base * (long) Math.pow(2, retryCount), unit)); .flatMap(retryCount -> Observable.timer(base * (long) Math.pow(2, retryCount), unit));
} }
public static <T> Single<T> lazy(Func0<Single<T>> func) {
return Single.just(true).flatMap(_junk -> func.call());
}
} }
...@@ -136,7 +136,7 @@ import rx.subjects.PublishSubject; ...@@ -136,7 +136,7 @@ import rx.subjects.PublishSubject;
} }
private Single<Boolean> connectToServerIfNeeded(String hostname) { private Single<Boolean> connectToServerIfNeeded(String hostname) {
return RxHelper.lazy(() -> { return Single.defer(() -> {
final int connectivity = serverConnectivityList.get(hostname); final int connectivity = serverConnectivityList.get(hostname);
if (connectivity == ServerConnectivity.STATE_CONNECTED) { if (connectivity == ServerConnectivity.STATE_CONNECTED) {
return Single.just(true); return Single.just(true);
...@@ -158,7 +158,7 @@ import rx.subjects.PublishSubject; ...@@ -158,7 +158,7 @@ import rx.subjects.PublishSubject;
} }
private Single<Boolean> disconnectFromServerIfNeeded(String hostname) { private Single<Boolean> disconnectFromServerIfNeeded(String hostname) {
return RxHelper.lazy(() -> { return Single.defer(() -> {
final int connectivity = serverConnectivityList.get(hostname); final int connectivity = serverConnectivityList.get(hostname);
if (connectivity == ServerConnectivity.STATE_DISCONNECTED) { if (connectivity == ServerConnectivity.STATE_DISCONNECTED) {
return Single.just(true); return Single.just(true);
...@@ -199,7 +199,7 @@ import rx.subjects.PublishSubject; ...@@ -199,7 +199,7 @@ import rx.subjects.PublishSubject;
} }
private Single<Boolean> connectToServer(String hostname) { private Single<Boolean> connectToServer(String hostname) {
return RxHelper.lazy(() -> { return Single.defer(() -> {
if (!serverConnectivityList.containsKey(hostname)) { if (!serverConnectivityList.containsKey(hostname)) {
return Single.error(new IllegalArgumentException("hostname not found")); return Single.error(new IllegalArgumentException("hostname not found"));
} }
...@@ -214,7 +214,7 @@ import rx.subjects.PublishSubject; ...@@ -214,7 +214,7 @@ import rx.subjects.PublishSubject;
} }
private Single<Boolean> disconnectFromServer(String hostname) { private Single<Boolean> disconnectFromServer(String hostname) {
return RxHelper.lazy(() -> { return Single.defer(() -> {
if (!serverConnectivityList.containsKey(hostname)) { if (!serverConnectivityList.containsKey(hostname)) {
return Single.error(new IllegalArgumentException("hostname not found")); return Single.error(new IllegalArgumentException("hostname not found"));
} }
......
...@@ -10,7 +10,6 @@ import android.support.annotation.Nullable; ...@@ -10,7 +10,6 @@ import android.support.annotation.Nullable;
import java.util.HashMap; import java.util.HashMap;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import chat.rocket.android.helper.RxHelper;
import hugo.weaving.DebugLog; import hugo.weaving.DebugLog;
import rx.Observable; import rx.Observable;
import rx.Single; import rx.Single;
...@@ -74,7 +73,7 @@ public class RocketChatService extends Service implements ConnectivityServiceInt ...@@ -74,7 +73,7 @@ public class RocketChatService extends Service implements ConnectivityServiceInt
@Override @Override
public Single<Boolean> disconnectFromServer(String hostname) { //called via binder. public Single<Boolean> disconnectFromServer(String hostname) { //called via binder.
return RxHelper.lazy(() -> { return Single.defer(() -> {
if (!webSocketThreads.containsKey(hostname)) { if (!webSocketThreads.containsKey(hostname)) {
return Single.just(true); return Single.just(true);
} }
...@@ -91,7 +90,7 @@ public class RocketChatService extends Service implements ConnectivityServiceInt ...@@ -91,7 +90,7 @@ public class RocketChatService extends Service implements ConnectivityServiceInt
@DebugLog @DebugLog
private Single<RocketChatWebSocketThread> getOrCreateWebSocketThread(String hostname) { private Single<RocketChatWebSocketThread> getOrCreateWebSocketThread(String hostname) {
return RxHelper.lazy(() -> { return Single.defer(() -> {
if (webSocketThreads.containsKey(hostname)) { if (webSocketThreads.containsKey(hostname)) {
RocketChatWebSocketThread thread = webSocketThreads.get(hostname); RocketChatWebSocketThread thread = webSocketThreads.get(hostname);
if (thread != null) { if (thread != null) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment