如果我理解正確的,你的觀測量的簽名類似於此:
// verifier Observables which perform network calls
Observable<Verification1> test1 = ...
Observable<Verification2> test2 = ...
...
// Observable to fire the transaction
Observable<TransactionResult> fireTransaction = ...
// represents the clicks on the "go" button of the UI
Observable<Void> goButtonClicks = ...
然後,你可以將所有這些觀測量如下:
goButtonClicks.flatMap(theVoid -> {
return Observable.zip(
test1.subscribeOn(Schedulers.io()),
test2.subscribeOn(Schedulers.io()),
(v1, v2) -> {
if (v1 and v2 pass all your requirements) {
return fireTransaction;
} else {
return Observable.just(new TransactionFailure("error"));
}
}
);
}).subscribe(transactionResult -> {
UI.showMessage(transactionResult.getMessage());
})
的.subscribeOn(Schedulers.io())
電話給你並行的驗證網絡調用,並且zip
允許您「等待」所有結果。
但是,我想在服務器端,出於安全考慮,您將不得不再次進行所有這些測試。因此,如果您可以更改體系結構,則可能需要始終「觸發」UI中的事務,讓服務器進行檢查,並將成功/失敗通知返回給UI。
非常感謝,我會試試這個!我無法更改服務器行爲,因爲它是第三方API。 –