【发布时间】:2019-02-23 01:25:25
【问题描述】:
我有以下同步代码,我想在 RXJava 中建模为异步代码。
void executeActions(List<Action> action) {
if (action == null || action.size() == 0) return;
for (Action action: actions) {
executeActions(action.handle());
}
}
class Action {
//implementation of handle
// return List<Action> or null.
List<Action> handle() {
}
}
现在在 JS 中,我可以像这样使用 Promises 对这种交互进行建模。 (下面的伪代码-我的JS很弱)
executeActionsAsync(actions) {
var p = Promise.resolve();
action.forEach(function(action) {
p = p.then(function() {
action.handle();
})
}
return p;
}
class Action() {
function handle() {
actions = [];// some array of actions.
executeAsync(actions);
}
}
我想在 RXJava2 中进行同样的建模。任何帮助表示赞赏。
【问题讨论】:
标签: java android promise rxjs rx-java2