diff --git a/lang/src/main/java/com/qwlabs/lang/QueueWorker.java b/lang/src/main/java/com/qwlabs/lang/QueueWorker.java index 9bf49a0..6b55f8e 100644 --- a/lang/src/main/java/com/qwlabs/lang/QueueWorker.java +++ b/lang/src/main/java/com/qwlabs/lang/QueueWorker.java @@ -110,6 +110,7 @@ private boolean execute(C context, int runs) { stopWatch.start("work"); executeBeforeEach(context, element); onWork.accept(context, element); + executeAfterEach(context, element); } catch (Exception e) { boolean shouldContinue = isContinue(context, element, e); executeOnFailed(context, element, e); @@ -118,7 +119,6 @@ private boolean execute(C context, int runs) { return false; } } finally { - executeAfterEach(context, element); stopWatch.stop(); } if (Objects.isNull(spinDuration)) { @@ -129,8 +129,8 @@ private boolean execute(C context, int runs) { private boolean isOutOfMaxRuns(int runs) { return Optional.ofNullable(maxRuns) - .map(mr -> mr < runs) - .orElse(false); + .map(mr -> mr < runs) + .orElse(false); } private void spin() { @@ -149,9 +149,9 @@ private void spin() { private boolean isContinue(C context, E element, Exception e) { return Objects.nonNull(element) - && Optional.ofNullable(continueWhen) - .map(f -> f.test(context, element, e)) - .orElse(true); + && Optional.ofNullable(continueWhen) + .map(f -> f.test(context, element, e)) + .orElse(true); } @FunctionalInterface