var state = [];
var operation1 = function() {
return Rx.Observable.fromPromise(new Promise((resolve, reject) => {
state.push(1, 2);
setTimeout(resolve, 300, state);
}));
};
var operation2 = function() {
return Rx.Observable.fromPromise(new Promise((resolve, reject) => {
state = state.map(x => x * 2);
setTimeout(resolve, 200, state);
}));
};
var operation3 = function() {
return Rx.Observable.fromPromise(new Promise((resolve, reject) => {
state = state.reduce( (prev, next) => prev + next );
setTimeout(resolve, 100, state);
}));
};
var operations = [operation1, operation2, operation3];
Given the code above, I am trying to combine operations
into one Observable
that emits the state of each operation. So the Observable
needs to do either one of the following:
- emits 3 times:
[1, 2], [2, 4], 6
- emits 1 time:
[[1, 2], [2, 4], 6]