// RxJS v6+import { interval } from'rxjs';import { take, ignoreElements } from'rxjs/operators';//매 100ms 간격으로 값을 내보냅니다constsource=interval(100);//완료인 경우를 제외하고, 모든 값들을 무시합니다constexample=source.pipe(take(5),ignoreElements());//결과: "COMPLETE!"constsubscribe=example.subscribe( val =>console.log(`NEXT: ${val}`), val =>console.log(`ERROR: ${val}`), () =>console.log('COMPLETE!'));
// RxJS v6+import { interval, throwError, of } from'rxjs';import { mergeMap, ignoreElements } from'rxjs/operators';//매 100ms 간격으로 값을 내보냅니다constsource=interval(100);//에러를 제외한 모든 것들을 무시합니다consterror=source.pipe(mergeMap(val => {if (val ===4) {returnthrowError(`ERROR AT ${val}`); }returnof(val); }),ignoreElements());//결과: "ERROR: ERROR AT 4"constsubscribe=error.subscribe( val =>console.log(`NEXT: ${val}`), val =>console.log(`ERROR: ${val}`), () =>console.log('SECOND COMPLETE!'));