简体   繁体   English

异步服务代理调用vertx

[英]Asynchronous service proxy calls vertx

I'm using service proxy library of vertx, and I'm having some trouble with the callback, my use case is : 我正在使用vertx的服务代理库,并且在回调时遇到了一些麻烦,我的用例是:

Q1 --> Q2 ---->Q3, what I have done so far is : Q1-> Q2 ----> Q3,到目前为止我做的是:

 insertOrUpdate(query, client, updateBuildingNode -> {

            if (updateBuildingNode.succeeded()) {

                userService.getUserbyId(user, getUserRes -> {

                    User currentUser = Json.decodeValue(getUserRes.result().get(0).toString(), User.class);
                    userService.removeNodeFromUser(new JsonObject().put("user", new JsonObject(Json.encode(currentUser))).put("nodeUid", buildingUid), removeNodeFromUserRes -> {

                        if (removeNodeFromUserRes.succeeded()) {
                            if(currentUser.getFavoriteBuilding()!=null && currentUser.getFavoriteBuilding().equalsIgnoreCase(buildingUid)) {


                                userService.removeNodeAsFavorite(new JsonObject().put("userUid", userUid).put("nodeUid", buildingUid), resultHandler);

                            }
                            else
                            {

                                resultHandler.handle(Future.succeededFuture(Boolean.TRUE));
                            }
                        } else {
                            resultHandler.handle(Future.failedFuture(removeNodeFromUserRes.cause()));
                        }
                    });


                });
            }
            else {
                resultHandler.handle(Future.failedFuture(updateBuildingNode.cause()));
            }

        });

My problem is that i want to do this calls like Q1 and Q2 wait for them to end and run Q3, and I have another request where I need to loop over Q[i] and wait for them all to them to do my logic. 我的问题是我想像Q1和Q2这样执行调用,以等待它们结束并运行Q3,并且还有另一个请求,我需要在Q [i]上循环并等待所有对它们执行我的逻辑。

I'm looking for something similar to angular js $q.all(q1,q2) 我正在寻找类似于angular js $q.all(q1,q2)

Any idea how can I do this in vertx and service proxy ? 知道如何在vertx和服务代理中执行此操作吗?

Have a look at the Async Coordination section in the docs. 看一下文档中的异步协调部分。 If you're often mixing different sources of events together you may also benefit from switching to the Vert.x API for RxJava . 如果经常将不同的事件源混合在一起,则可能会受益于切换到RxJavaVert.x API

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

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