Skip to content

Commit

Permalink
don't throw exception if promise is already resolved or rejected
Browse files Browse the repository at this point in the history
  • Loading branch information
anbui authored and anbui committed Nov 10, 2018
1 parent 6246a51 commit bf94110
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/joo/promise4j/impl/AsyncDeferredObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public AsyncDeferredObject() {
@Override
public Deferred<D, F> resolve(final D result) {
if (!done.compareAndSet(false, true))
throw new IllegalStateException("Deferred is already resolved or rejected");
return this;
this.result = result;
this.status = DeferredStatus.RESOLVED;
this.onComplete(result);
Expand All @@ -55,7 +55,7 @@ public Deferred<D, F> resolve(final D result) {
@Override
public Deferred<D, F> reject(final F failedCause) {
if (!done.compareAndSet(false, true))
throw new IllegalStateException("Deferred is already resolved or rejected");
return this;
this.failedCause = failedCause;
this.status = DeferredStatus.REJECTED;
this.onFail(failedCause);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/joo/promise4j/impl/SyncDeferredObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class SyncDeferredObject<D, F extends Throwable> extends AbstractPromise<
public Deferred<D, F> resolve(final D resolve) {
synchronized (this) {
if (!isPending())
throw new IllegalStateException("Deferred is already resolved or rejected");
return this;

this.status = DeferredStatus.RESOLVED;
this.result = resolve;
Expand All @@ -46,7 +46,7 @@ public Deferred<D, F> resolve(final D resolve) {
public Deferred<D, F> reject(final F reject) {
synchronized (this) {
if (!isPending())
throw new IllegalStateException("Deferred is already resolved or rejected");
return this;

this.status = DeferredStatus.REJECTED;
this.failedCause = reject;
Expand Down

0 comments on commit bf94110

Please sign in to comment.