signature: toPromise() : Promise
//옵저버블을 리턴
const sample = val => Rx.Observable.of(val).delay(5000);
//옵저버블을 프로미스로 변환
const example = sample('First Example')
.toPromise()
//결과: 'First Example'
.then(result => {
console.log('From Promise:', result);
});
// 옵저버블을 리턴
const sample = val => Rx.Observable.of(val).delay(5000);
/*
각각을 프로미스로 바꾸고, Promise.all을 사용하여 모두 resolve되기를 기다립니다
*/
const example = () => {
return Promise.all([
sample('Promise 1').toPromise(),
sample('Promise 2').toPromise()
]);
};
//결과: ["Promise 1", "Promise 2"]
example().then(val => {
console.log('Promise.all Result:', val);
});