mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-19 02:22:05 +01:00
Merge pull request #510 from Flowdalic/future-invoke-at-most-once
[SmackFuture] Invoke the callbacks at most once
This commit is contained in:
commit
e25be8fea4
1 changed files with 6 additions and 1 deletions
|
@ -162,16 +162,20 @@ public abstract class SmackFuture<V, E extends Exception> implements Future<V>,
|
|||
return result;
|
||||
}
|
||||
|
||||
private boolean callbacksInvoked;
|
||||
|
||||
protected final synchronized void maybeInvokeCallbacks() {
|
||||
if (cancelled) {
|
||||
if (cancelled || callbacksInvoked) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((result != null || exception != null) && completionCallback != null) {
|
||||
callbacksInvoked = true;
|
||||
completionCallback.accept(this);
|
||||
}
|
||||
|
||||
if (result != null && successCallback != null) {
|
||||
callbacksInvoked = true;
|
||||
AbstractXMPPConnection.asyncGo(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -180,6 +184,7 @@ public abstract class SmackFuture<V, E extends Exception> implements Future<V>,
|
|||
});
|
||||
}
|
||||
else if (exception != null && exceptionCallback != null) {
|
||||
callbacksInvoked = true;
|
||||
AbstractXMPPConnection.asyncGo(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
Loading…
Reference in a new issue