azelix
azelix

Reputation: 1277

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 :

Q1 --> Q2 ---->Q3, what I have done so far is :

 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.

I'm looking for something similar to angular js $q.all(q1,q2)

Any idea how can I do this in vertx and service proxy ?

Upvotes: 1

Views: 297

Answers (1)

tsegismont
tsegismont

Reputation: 9128

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.

Upvotes: 4

Related Questions