This commit is contained in:
Andrea Cavalli 2021-04-18 23:27:23 +02:00
parent 0f1c2ed0fa
commit a855b4fdba
2 changed files with 16 additions and 6 deletions

View File

@ -231,10 +231,11 @@ public class InternalReactiveClient implements ClientEventsHandler, ReactiveTele
var subscription = new Subscription() {
private final AtomicBoolean alreadyRequested = new AtomicBoolean(false);
private volatile boolean cancelled = false;
@Override
public void request(long n) {
if (alreadyRequested.compareAndSet(false, true)) {
if (n > 0 && alreadyRequested.compareAndSet(false, true)) {
if (isClosedAndMaybeThrow(query)) {
logger.trace("Client {} is already closed, sending \"Ok\" to: {}", clientId, query);
subscriber.onNext(new TdApi.Ok());
@ -247,9 +248,17 @@ public class InternalReactiveClient implements ClientEventsHandler, ReactiveTele
} else {
long queryId = clientManager.getNextQueryId();
handlers.put(queryId, new Handler(result -> {
if (!cancelled) {
subscriber.onNext(result);
}
if (!cancelled) {
subscriber.onComplete();
}, subscriber::onError));
}
}, t -> {
if (!cancelled) {
subscriber.onError(t);
}
}));
logger.trace("Client {} is requesting with query id {}: {}", clientId, queryId, query);
NativeClientAccess.send(clientId, queryId, query);
logger.trace("Client {} requested with query id {}: {}", clientId, queryId, query);
@ -261,6 +270,7 @@ public class InternalReactiveClient implements ClientEventsHandler, ReactiveTele
@Override
public void cancel() {
cancelled = true;
}
};
subscriber.onSubscribe(subscription);