mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 20:22:07 +08:00
feature #I7HJFX 封装ForCondition,IteratorCondition,WhileCondition中冗余代码到LoopCondition中
This commit is contained in:
@@ -93,15 +93,7 @@ public class ForCondition extends LoopCondition {
|
||||
}
|
||||
}
|
||||
//等待所有的异步执行完毕
|
||||
CompletableFuture<?> resultCompletableFuture = CompletableFuture.allOf(futureList.toArray(new CompletableFuture[]{}));
|
||||
resultCompletableFuture.join();
|
||||
//获取所有的执行结果,如果有失败的,那么需要抛出异常
|
||||
for (CompletableFuture<LoopFutureObj> future : futureList) {
|
||||
LoopFutureObj loopFutureObj = future.get();
|
||||
if (!loopFutureObj.isSuccess()) {
|
||||
throw loopFutureObj.getEx();
|
||||
}
|
||||
}
|
||||
handleFutureList(futureList);
|
||||
}
|
||||
} finally {
|
||||
removeLoopIndex(executableItem);
|
||||
|
||||
@@ -99,15 +99,7 @@ public class IteratorCondition extends LoopCondition {
|
||||
index++;
|
||||
}
|
||||
//等待所有的异步执行完毕
|
||||
CompletableFuture<?> resultCompletableFuture = CompletableFuture.allOf(futureList.toArray(new CompletableFuture[]{}));
|
||||
resultCompletableFuture.join();
|
||||
//获取所有的执行结果,如果有失败的,那么需要抛出异常
|
||||
for (CompletableFuture<LoopFutureObj> future : futureList) {
|
||||
LoopFutureObj loopFutureObj = future.get();
|
||||
if (!loopFutureObj.isSuccess()) {
|
||||
throw loopFutureObj.getEx();
|
||||
}
|
||||
}
|
||||
handleFutureList(futureList);
|
||||
}
|
||||
} finally {
|
||||
removeLoopIndex(executableItem);
|
||||
|
||||
@@ -6,6 +6,8 @@ import com.yomahub.liteflow.flow.element.Executable;
|
||||
import com.yomahub.liteflow.flow.element.Node;
|
||||
import com.yomahub.liteflow.flow.parallel.LoopFutureObj;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
@@ -86,6 +88,19 @@ public abstract class LoopCondition extends Condition {
|
||||
this.parallel = parallel;
|
||||
}
|
||||
|
||||
//循环并行执行的futureList处理
|
||||
protected void handleFutureList(List<CompletableFuture<LoopFutureObj>> futureList)throws Exception{
|
||||
CompletableFuture<?> resultCompletableFuture = CompletableFuture.allOf(futureList.toArray(new CompletableFuture[]{}));
|
||||
resultCompletableFuture.join();
|
||||
//获取所有的执行结果,如果有失败的,那么需要抛出异常
|
||||
for (CompletableFuture<LoopFutureObj> future : futureList) {
|
||||
LoopFutureObj loopFutureObj = future.get();
|
||||
if (!loopFutureObj.isSuccess()) {
|
||||
throw loopFutureObj.getEx();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 循环并行执行的Supplier封装
|
||||
public class LoopParallelSupplier implements Supplier<LoopFutureObj> {
|
||||
private final Executable executableItem;
|
||||
|
||||
@@ -77,15 +77,7 @@ public class WhileCondition extends LoopCondition {
|
||||
index++;
|
||||
}
|
||||
//等待所有的异步执行完毕
|
||||
CompletableFuture<?> resultCompletableFuture = CompletableFuture.allOf(futureList.toArray(new CompletableFuture[]{}));
|
||||
resultCompletableFuture.join();
|
||||
//获取所有的执行结果,如果有失败的,那么需要抛出异常
|
||||
for (CompletableFuture<LoopFutureObj> future : futureList) {
|
||||
LoopFutureObj loopFutureObj = future.get();
|
||||
if (!loopFutureObj.isSuccess()) {
|
||||
throw loopFutureObj.getEx();
|
||||
}
|
||||
}
|
||||
handleFutureList(futureList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user