Performance improvement
This commit is contained in:
parent
714081a93c
commit
b4d53393fe
|
@ -259,8 +259,8 @@ public class AsyncTdEasy {
|
||||||
public Mono<String> getOptionString(String name) {
|
public Mono<String> getOptionString(String name) {
|
||||||
return this
|
return this
|
||||||
.<TdApi.OptionValue>sendDirectly(new TdApi.GetOption(name), DEFAULT_TIMEOUT, false)
|
.<TdApi.OptionValue>sendDirectly(new TdApi.GetOption(name), DEFAULT_TIMEOUT, false)
|
||||||
.flatMap(MonoUtils::orElseThrow)
|
.<TdApi.OptionValue>handle(MonoUtils::orElseThrow)
|
||||||
.flatMap((TdApi.OptionValue value) -> {
|
.flatMap(value -> {
|
||||||
switch (value.getConstructor()) {
|
switch (value.getConstructor()) {
|
||||||
case OptionValueString.CONSTRUCTOR:
|
case OptionValueString.CONSTRUCTOR:
|
||||||
return Mono.just(((OptionValueString) value).value);
|
return Mono.just(((OptionValueString) value).value);
|
||||||
|
@ -281,8 +281,8 @@ public class AsyncTdEasy {
|
||||||
public Mono<Long> getOptionInteger(String name) {
|
public Mono<Long> getOptionInteger(String name) {
|
||||||
return this
|
return this
|
||||||
.<TdApi.OptionValue>sendDirectly(new TdApi.GetOption(name), DEFAULT_TIMEOUT, false)
|
.<TdApi.OptionValue>sendDirectly(new TdApi.GetOption(name), DEFAULT_TIMEOUT, false)
|
||||||
.flatMap(MonoUtils::orElseThrow)
|
.<TdApi.OptionValue>handle(MonoUtils::orElseThrow)
|
||||||
.flatMap((TdApi.OptionValue value) -> {
|
.flatMap(value -> {
|
||||||
switch (value.getConstructor()) {
|
switch (value.getConstructor()) {
|
||||||
case OptionValueInteger.CONSTRUCTOR:
|
case OptionValueInteger.CONSTRUCTOR:
|
||||||
return Mono.just(((OptionValueInteger) value).value);
|
return Mono.just(((OptionValueInteger) value).value);
|
||||||
|
@ -303,8 +303,8 @@ public class AsyncTdEasy {
|
||||||
public Mono<Boolean> getOptionBoolean(String name) {
|
public Mono<Boolean> getOptionBoolean(String name) {
|
||||||
return this
|
return this
|
||||||
.<TdApi.OptionValue>sendDirectly(new TdApi.GetOption(name), DEFAULT_TIMEOUT, false)
|
.<TdApi.OptionValue>sendDirectly(new TdApi.GetOption(name), DEFAULT_TIMEOUT, false)
|
||||||
.flatMap(MonoUtils::orElseThrow)
|
.<TdApi.OptionValue>handle(MonoUtils::orElseThrow)
|
||||||
.flatMap((TdApi.OptionValue value) -> {
|
.flatMap(value -> {
|
||||||
switch (value.getConstructor()) {
|
switch (value.getConstructor()) {
|
||||||
case OptionValueBoolean.CONSTRUCTOR:
|
case OptionValueBoolean.CONSTRUCTOR:
|
||||||
return Mono.just(((OptionValueBoolean) value).value);
|
return Mono.just(((OptionValueBoolean) value).value);
|
||||||
|
|
|
@ -16,7 +16,6 @@ import io.vertx.reactivex.core.streams.ReadStream;
|
||||||
import io.vertx.reactivex.core.streams.WriteStream;
|
import io.vertx.reactivex.core.streams.WriteStream;
|
||||||
import it.tdlight.jni.TdApi;
|
import it.tdlight.jni.TdApi;
|
||||||
import it.tdlight.jni.TdApi.Chat;
|
import it.tdlight.jni.TdApi.Chat;
|
||||||
import it.tdlight.jni.TdApi.Object;
|
|
||||||
import it.tdlight.tdlibsession.td.TdError;
|
import it.tdlight.tdlibsession.td.TdError;
|
||||||
import it.tdlight.tdlibsession.td.TdResult;
|
import it.tdlight.tdlibsession.td.TdResult;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
@ -86,11 +85,11 @@ public class MonoUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <R extends TdApi.Object> Mono<R> orElseThrow(TdResult<R> value) {
|
public static <T extends TdApi.Object> void orElseThrow(TdResult<T> value, SynchronousSink<T> sink) {
|
||||||
if (value.succeeded()) {
|
if (value.succeeded()) {
|
||||||
return Mono.just(value.result());
|
sink.next(value.result());
|
||||||
} else {
|
} else {
|
||||||
return Mono.error(new TdError(value.cause().code, value.cause().message));
|
sink.error(new TdError(value.cause().code, value.cause().message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue