异步任务流程编排

查看 27|回复 2
作者:Edsie   
最近需要写一个 mock 工具,其中需要对一系列的动作进行编排和模拟,在使用 Java 的 CompletableFuture 时,发现缺少一下方法,自己 wrap 了下提供几个拓展方法,用法如下
CompletableFutureEx
        .runAsync(() -> print("one"))
        .thenRunAsync(() -> print("two"))
        .thenRunWithRetry(500, i -> {
            print("three: retry " + i);
            return i > 5;
        })
        .thenWaitMills(1000)
        .thenRunAsync(() -> print("four"))
        .thenWaitSignal(signal)
        .thenRunAsync(() -> print("five"));
完整代码在: https://gist.github.com/haomega/cfae14f47054e36d7c3ae4ac3e7cf90b
还有更好的方法或工具么,目前 cancel 貌似不太方便,不能简单的 cancel 掉一个完整的链路
如果是其他语言( golang )应该怎么写
rexinshimin   
京东好像有一款,不过看样子,很久不更新了。可参考一下。https://gitee.com/jd-platform-opensource/asyncTool
yazinnnn0   
https://www.reactivemanifesto.org/zh-CN
https://www.reactive-streams.org/
这个?
reactivex 有大多数语言的 reactive 实现, 包括 go
jvm 上的 reactive 实现还有 reactor smallrye-mutiny kotlin 协程
您需要登录后才可以回帖 登录 | 立即注册

返回顶部