Skip to content

Instantly share code, notes, and snippets.

@DevWurm

DevWurm/obsall.ts

Created Apr 3, 2017
Embed
What would you like to do?
Promise.all and promise.then(...).then(...) behavior for Observables
const create = (val) => {
return (o: Observer<any>) => {
setTimeout(() => {
console.log(val);
o.next(val);
o.complete();
}, 5000)
}
};
const f1 = () => {
return Observable.create(create(1));
};
const f2 = () => {
return Observable.create(create(2));
};
const f3 = () => {
return Observable.create(create(3));
};
// promise.then(...).then(...)
f1().flatMap(f2).flatMap(f3).subscribe((vals) => console.log("Subscribe:", vals));
// Promise.all
Observable.forkJoin(...[f1(), f2(), f3()]).subscribe((vals) => console.log("Subscribe:", vals));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.