@@ -230,37 +230,43 @@ private static ImmutableList<SpawnResult> waitBranch(Future<ImmutableList<SpawnR
230
230
* <p>This guarantees that the two branches are stopped both on successful termination and on an
231
231
* exception.
232
232
*
233
- * @param branch1 the future running one side of the spawn (e.g. local) . This future must cancel
234
- * {@code branch2 } at some point during its successful execution to guarantee termination. If
235
- * we encounter an execution error, or if we are interrupted, then we handle such cancellation
236
- * here.
237
- * @param branch2 the future running the other side of the spawn (e.g. remote). Same restrictions
238
- * apply as in {@code branch1 }, but in the symmetric direction.
233
+ * @param localBranch the future running the local side of the spawn. This future must cancel
234
+ * {@code remoteBranch } at some point during its successful execution to guarantee
235
+ * termination. If we encounter an execution error, or if we are interrupted, then we handle
236
+ * such cancellation here.
237
+ * @param remoteBranch the future running the remote side of the spawn. Same restrictions apply as
238
+ * in {@code localBranch }, but in the symmetric direction.
239
239
* @return the result of the branch that terminates first
240
240
* @throws ExecException the execution error of the spawn that terminated first
241
241
* @throws InterruptedException if we get interrupted while waiting for completion
242
242
*/
243
243
private static ImmutableList <SpawnResult > waitBranches (
244
- Future <ImmutableList <SpawnResult >> branch1 , Future <ImmutableList <SpawnResult >> branch2 )
244
+ Future <ImmutableList <SpawnResult >> localBranch ,
245
+ Future <ImmutableList <SpawnResult >> remoteBranch )
245
246
throws ExecException , InterruptedException {
246
- ImmutableList <SpawnResult > result1 ;
247
+ ImmutableList <SpawnResult > localResult ;
247
248
try {
248
- result1 = waitBranch (branch1 );
249
+ localResult = waitBranch (localBranch );
249
250
} catch (ExecException | InterruptedException | RuntimeException e ) {
250
- branch2 .cancel (true );
251
+ remoteBranch .cancel (true );
251
252
throw e ;
252
253
}
253
254
254
- ImmutableList <SpawnResult > result2 = waitBranch (branch2 );
255
+ ImmutableList <SpawnResult > remoteResult = waitBranch (remoteBranch );
255
256
256
- if (result2 != null && result1 != null ) {
257
+ if (remoteResult != null && localResult != null ) {
257
258
throw new AssertionError ("One branch did not cancel the other one" );
258
- } else if (result2 != null ) {
259
- return result2 ;
260
- } else if (result1 != null ) {
261
- return result1 ;
259
+ } else if (remoteResult != null ) {
260
+ return remoteResult ;
261
+ } else if (localResult != null ) {
262
+ return localResult ;
262
263
} else {
263
- throw new AssertionError ("No branch completed, which might mean they cancelled each other" );
264
+ throw new AssertionError (
265
+ "Neither branch completed. Local was "
266
+ + (localBranch .isCancelled () ? "" : "not " )
267
+ + "cancelled and remote was "
268
+ + (remoteBranch .isCancelled () ? "" : "not " )
269
+ + "cancelled" );
264
270
}
265
271
}
266
272
0 commit comments