简体   繁体   English

异步垂直与复合未来垂直。 它们有何不同?

[英]Async Verticle vs Composite Future Verticle. How are they different?

I have two Hello World handle methods written in Kotlin Vert.x.我有两个用 Kotlin Vert.x 编写的 Hello World 句柄方法。 I want to get a clear understanding of how they are working, if possible in detail.如果可能的话,我想清楚地了解它们是如何工作的。 One is AsyncVertilce while other is CompositeVerticle.一个是 AsyncVertilce 而另一个是 CompositeVerticle。

This one is Hello World Coroutine Async Verticle handle method.这是Hello World Coroutine Async Verticle句柄方法。

    var result = async {
        callFunctionAwait(
            getDependentAddress(HELLO_WORLD), message.headers(), message.body(), messageMarker
        )
    }

    var result1 = async {
        callFunctionAwait(
            getDependentAddress(HELLO_WORLD), message.headers(), message.body(), messageMarker
        )
    }

    // both requests are going to execute in parallel
    val res = result.await()
    val res1 = result1.await()
    message.reply(res.body, DeliveryOptions().setHeaders(res1.headers))

}

This one is Hello World Coroutine Composite Verticle这是Hello World Coroutine Composite Verticle

    var future1 = callFunction(getDependentAddress(HELLO_WORLD), message.headers(), message.body(), messageMarker)
    var future2 = callFunction(getDependentAddress(HELLO_WORLD), message.headers(), message.body(), messageMarker)

    val result = CompositeFuture.all(future1, future2).await()
    if (result.succeeded()) {
        message.reply(future1.result().body, DeliveryOptions().setHeaders(future2.result().headers))
    } else {
        log.error(messageMarker, "Request failed with an exception ", result.cause())
        message.fail(500, result.cause().message)
    }
}

From the documentation文档

CompositeFuture.all() takes several futures arguments (up to 6) and returns a future that is succeeded when all the futures are succeeded and failed when at least one of the futures is failed CompositeFuture.all() 接受多个期货参数(最多 6 个)并返回一个期货,当所有期货成功时成功,当至少有一个期货失败时返回失败

One of the main use cases is when you want all or nothing operations;主要用例之一是当您想要全有或全无操作时; when you expect a single result for a given number of futures.当您期望给定数量的期货有单一结果时。

There are other variants of CompositeFuture like CompositeFuture.any and CompositeFuture.join CompositeFuture还有其他变体,如CompositeFuture.anyCompositeFuture.join

The async way of executing futures, will run each future individually and their results will be gotten irrespective of the other future(s).执行期货的async方式,将单独运行每个期货,并且无论其他期货如何,都将获得它们的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM