Skip to content

Commit

Permalink
Serialize onCompleteFailure for #9059
Browse files Browse the repository at this point in the history
  • Loading branch information
gregw committed Dec 16, 2022
1 parent 6e82e70 commit 0ada3d4
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ protected enum Action

private final AutoLock _lock = new AutoLock();
private State _state;
private Throwable _failure;
private boolean _iterate;

protected IteratingCallback()
Expand Down Expand Up @@ -220,6 +221,7 @@ private void processing()
// may happen concurrently, so state is not assumed.

boolean onCompleteSuccess = false;
Throwable onCompleteFailure = null;

// While we are processing
processing:
Expand Down Expand Up @@ -254,7 +256,7 @@ private void processing()
// yes, so skip idle and keep processing
_iterate = false;
_state = State.PROCESSING;
continue processing;
continue;
}

// No, so we can go idle
Expand Down Expand Up @@ -290,11 +292,15 @@ private void processing()
throw new IllegalStateException(String.format("%s[action=%s]", this, action));
// we lost the race, so we have to keep processing
_state = State.PROCESSING;
continue processing;
continue;
}

case SUCCEEDED:
case FAILED:
onCompleteFailure = _failure;
_failure = null;
break processing;

case SUCCEEDED:
case CLOSED:
break processing;

Expand All @@ -308,6 +314,8 @@ private void processing()

if (onCompleteSuccess)
onCompleteSuccess();
else if (onCompleteFailure != null)
onCompleteFailure(onCompleteFailure);
}

/**
Expand Down Expand Up @@ -370,12 +378,15 @@ public void failed(Throwable x)
case CALLED:
// too late!.
break;

case PENDING:
{
failure = true;
break;
}
case PROCESSING:
{
_state = State.FAILED;
failure = true;
_failure = x;
break;
}
default:
Expand Down

0 comments on commit 0ada3d4

Please sign in to comment.