#36 rxjava: single
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package org.example.ex05;
|
||||
|
||||
import io.reactivex.rxjava3.annotations.NonNull;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import io.reactivex.rxjava3.core.SingleEmitter;
|
||||
import io.reactivex.rxjava3.core.SingleObserver;
|
||||
import io.reactivex.rxjava3.core.SingleOnSubscribe;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
import org.example.utils.DateUtil;
|
||||
import org.example.utils.LogType;
|
||||
import org.example.utils.Logger;
|
||||
|
||||
public class SingleCreateEx {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Single<String> single = Single.create(new SingleOnSubscribe<String>() {
|
||||
@Override
|
||||
public void subscribe(@NonNull SingleEmitter<String> emitter) throws Throwable {
|
||||
emitter.onSuccess(DateUtil.getNowDate());
|
||||
}
|
||||
});
|
||||
|
||||
single.subscribe(new SingleObserver<String>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(@NonNull String s) {
|
||||
Logger.log(LogType.ON_SUCCESS, "# 날짜시간: " + s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Logger.log(LogType.ON_ERROR, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.example.ex05;
|
||||
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import org.example.utils.DateUtil;
|
||||
import org.example.utils.LogType;
|
||||
import org.example.utils.Logger;
|
||||
|
||||
public class SingleCreateLambdaEx {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Single<String> single = Single.create(emitter -> emitter.onSuccess(DateUtil.getNowDate()));
|
||||
|
||||
single.subscribe(
|
||||
data -> Logger.log(LogType.ON_SUCCESS, "# 날짜시간: " + data),
|
||||
error -> Logger.log(LogType.ON_ERROR, error)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.example.ex05;
|
||||
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import org.example.utils.DateUtil;
|
||||
import org.example.utils.LogType;
|
||||
import org.example.utils.Logger;
|
||||
|
||||
public class SingleJustEx {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Single.just(DateUtil.getNowDate())
|
||||
.subscribe(
|
||||
data -> Logger.log(LogType.ON_SUCCESS, "# 날짜시간: " + data),
|
||||
error -> Logger.log(LogType.ON_ERROR, error)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user