我在想什麼是在Vert.x中異步運行以下一組調用的最佳方法。如何在Vert.x中有效地編程組合協調
C1: [v1, v2] +--> C2(v1): x --> C2.1(x): xx --|
|--> C3(v2): y --> C3.1(y): yy --+- C4(xx, yy)
至於符號C1: [v1, v2]
意味着呼叫C1
返回值[v1, v2]
的陣列。
我在想什麼,此刻是:
Future c1 = Future.future();
call_C1(some_input, handler -> {
// ... do something
c1.complete([v1, v2]);
});
c1.compose(array -> {
// process data and then call C2-->C2.1 and C3-->C3.1
Future c2 = Future.future();
call_C2(array[0], c2.completer());
Future c21 = Future.future();
c2.compose(x -> {
// process x and then call C2.1
call_C2_1(x, h -> {
// process result and complete c21
c21.complete(xx);
});
});
Future c3 = Future.future();
call_C3(array[1], c3.completer());
Future c31 = Future.future();
c3.compose(y -> {
// process y and then call C3.1
call_C3_1(y, h -> {
c31.complete(yy);
});
});
CompositeFuture.all(c21, c31).setHandler(h -> {
xx = h.result().resultAt(0);
yy = h.result().resultAt(1);
// process xx and yy
});
});
我希望這是正確的,但在那裏將所有這些呼叫組合更好,更自然或更有效的方法是什麼?任何幫助讚賞。
它看起來是正確的,但它缺少的C4電話:)有沒有「更好」的方式,但你可以考慮看RxJava和Vert.x rxified API,這對你來說可能更自然。 – tsegismont
好點!現在,我正在摸索如何用頂層'c1'來編寫C4調用,而不是將它嵌入複合未來處理程序中。無論如何,你是否能夠在RxJava + Vert.x中顯示「等效」複合調用?提前致謝。 – Jacek