I'm creating an array of asynchronous observables with Rx.Observable.create()
and hope to use .toArray()
to get all the values when they complete.
console.log('running');
let valsArray = ['a','b','c'].map((val,i)=>{
return Rx.Observable.create((obs)=>{
let tid = setTimeout(()=>{
console.log(val + ' timing out');
obs.onNext(val);
},i*500);
return ()=>{
clearTimeout(tid);
};
}).publish().refCount();
});
Rx.Observable.from(valsArray)
.flatMap((v)=>v)
.toArray()
.subscribe((arr)=>{
console.log("arr should be ['a','b','c']",arr);
});
Above example at http://jsbin.com/wegoha/10/edit?js,console.
Using setTimeout
as a stand-in for other asynchronous operations to keep the example simple.