Merge pull request #510 from Flowdalic/future-invoke-at-most-once

[SmackFuture] Invoke the callbacks at most once
This commit is contained in:
Florian Schmaus 2022-02-03 07:58:19 +01:00 committed by GitHub
commit e25be8fea4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -162,16 +162,20 @@ public abstract class SmackFuture<V, E extends Exception> implements Future<V>,
return result; return result;
} }
private boolean callbacksInvoked;
protected final synchronized void maybeInvokeCallbacks() { protected final synchronized void maybeInvokeCallbacks() {
if (cancelled) { if (cancelled || callbacksInvoked) {
return; return;
} }
if ((result != null || exception != null) && completionCallback != null) { if ((result != null || exception != null) && completionCallback != null) {
callbacksInvoked = true;
completionCallback.accept(this); completionCallback.accept(this);
} }
if (result != null && successCallback != null) { if (result != null && successCallback != null) {
callbacksInvoked = true;
AbstractXMPPConnection.asyncGo(new Runnable() { AbstractXMPPConnection.asyncGo(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -180,6 +184,7 @@ public abstract class SmackFuture<V, E extends Exception> implements Future<V>,
}); });
} }
else if (exception != null && exceptionCallback != null) { else if (exception != null && exceptionCallback != null) {
callbacksInvoked = true;
AbstractXMPPConnection.asyncGo(new Runnable() { AbstractXMPPConnection.asyncGo(new Runnable() {
@Override @Override
public void run() { public void run() {