Skip to content

Commit

Permalink
Fix missing rejection of next promise if callback returns a promise w…
Browse files Browse the repository at this point in the history
…hich is rejected
  • Loading branch information
code77se committed Feb 17, 2016
1 parent 78e666a commit c7d6ea3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion jq/src/main/java/se/code77/jq/PromiseImpl.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

package se.code77.jq;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -229,7 +231,7 @@ public boolean isDone() {

@Override
public String toString() {
return getLogPrefix() + mState.toString();
return getLogPrefix() + mState.toString() + (mTerminate ? ", TERMINATE" : "");
}

private void ensurePending() {
Expand Down Expand Up @@ -337,13 +339,23 @@ public Future onFulfilled(Object value) throws Exception {
link.nextPromise._resolve(value);
return null;
}
}, new OnRejectedCallback() {
@Override
public Future onRejected(Exception reason) throws Exception {
link.nextPromise._reject(reason);
return null;
}
}).done();
} else {
link.nextPromise._resolve(null);
}
} catch (UnhandledRejectionException e) {
throw e;
} catch (Exception reason) {
StringWriter sw = new StringWriter();
reason.printStackTrace(new PrintWriter(sw));
debug("Promise rejected from callback: " + sw.toString());

link.nextPromise._reject(reason);
}
}
Expand Down

0 comments on commit c7d6ea3

Please sign in to comment.