public void compensate()

in src/main/java/com/uber/cadence/workflow/Saga.java [104:140]


  public void compensate() {
    if (options.parallelCompensation) {
      List<Promise> results = new ArrayList<>();
      for (Functions.Func<Promise> f : compensationOps) {
        results.add(f.apply());
      }

      CompensationException sagaException = null;
      for (Promise p : results) {
        try {
          p.get();
        } catch (Exception e) {
          if (sagaException == null) {
            sagaException = new CompensationException(e);
          } else {
            sagaException.addSuppressed(e);
          }
        }
      }

      if (sagaException != null) {
        throw sagaException;
      }
    } else {
      for (int i = compensationOps.size() - 1; i >= 0; i--) {
        Functions.Func<Promise> f = compensationOps.get(i);
        try {
          Promise result = f.apply();
          result.get();
        } catch (Exception e) {
          if (!options.continueWithError) {
            throw e;
          }
        }
      }
    }
  }