V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
Edsie
V2EX  ›  程序员

异步任务流程编排

  •  
  •   Edsie · Dec 16, 2024 · 2417 views
    This topic created in 501 days ago, the information mentioned may be changed or developed.

    最近需要写一个 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 )应该怎么写

    6 replies    2024-12-17 15:38:42 +08:00
    rexinshimin
        1
    rexinshimin  
       Dec 16, 2024
    京东好像有一款,不过看样子,很久不更新了。可参考一下。https://gitee.com/jd-platform-opensource/asyncTool
    yazinnnn0
        2
    yazinnnn0  
       Dec 16, 2024
    https://www.reactivemanifesto.org/zh-CN
    https://www.reactive-streams.org/

    这个?

    reactivex 有大多数语言的 reactive 实现, 包括 go
    jvm 上的 reactive 实现还有 reactor smallrye-mutiny kotlin 协程
    Edsie
        3
    Edsie  
    OP
       Dec 16, 2024
    @yazinnnn0 看起来是的
    ychost
        4
    ychost  
       Dec 16, 2024
    kotlin 就很好实现,开个 Coroutine 得到 job 随时可以 cancel ,Java 要实现建议用 reactive 吧这个更成熟
    securityCoding
        5
    securityCoding  
       Dec 16, 2024
    编排的话看看 dag 这块有没有的合适库
    CynicalRose
        6
    CynicalRose  
       Dec 17, 2024
    reactive 那套真的要了老命了,write once spring gateway ,debug everywhere 🤣
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2481 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 09:57 · PVG 17:57 · LAX 02:57 · JFK 05:57
    ♥ Do have faith in what you're doing.