我有两个基于异步FileReader操作的rxjs Observable。每个订阅都单独完成,但我尝试.subscribe
它们永远不会执行其let observe1 = this.Service1.parsedResponse$;
let observe2 = this.Service2.parsedResponse$;
observe1.subscribe((data) => {
console.log('subscription 1', data); // this executes
});
observe2.subscribe((data) => {
console.log('subscription 2', data); // this executes
});
let observeJoined = Observable.forkJoin(observe1, observe2);
observeJoined.subscribe((data: Object[]) => {
console.log('are we forkjoined?', data); // never happens
});
方法。显然我错了;继承人代码:
public interface Function<T, R> {
/**
* Applies this function to the given argument.
*
* @param t the function argument
* @return the function result
*/
R apply(T t);
}
public static <T, O> List<T> extract(Collection<O> collection, Function<O, T> mapper) {
List<T> result = new ArrayList<>(collection.size());
for (O o : collection) {
result.add(mapper.apply(o));
}
return result;
}
我理想的只是两个对象(data1,data2);它们不需要合并为一个结果。在继续之前我只需要知道我有两个。谢谢!
答案 0 :(得分:0)
试试这个:
var source = Rx.Observable.forkJoin(
this.Service1.parsedResponse$,
this.Service2.parsedResponse$
);
var subscription = source.subscribe(
function (x) {
console.log('Next: %s', x);
},
function (err) {
console.log('Error: %s', err);
},
function () {
console.log('Completed');
});