toPromise
signature: toPromise() : Promise
Example 1: Basic Promise
Example 2: Using Promise.all
import { of } from 'rxjs/observable/of';
import { delay } from 'rxjs/operators';
//return basic observable
const sample = val => of(val).pipe(delay(5000));
convert each to promise and use Promise.all
to wait for all to resolve
*/
const example = () => {
return Promise.all([
]);
};
//output: ["Promise 1", "Promise 2"]
example().then(val => {
console.log('Promise.all Result:', val);
});
Additional Resources
- toPromise
- Official Docs