ignoreElements
연산자(operator) 정의: ignoreElements(): Observable
Ignore everything but complete and error.
Examples
Example 1: Ignore all elements from source
//emit value every 100ms
const source = Rx.Observable.interval(100);
//ignore everything but complete
const example = source
.take(5)
.ignoreElements();
//output: "COMPLETE!"
const subscribe = example.subscribe(
val => console.log(`NEXT: ${val}`),
val => console.log(`ERROR: ${val}`),
() => console.log('COMPLETE!')
);
Example 2: Only displaying error
//emit value every 100ms
const source = Rx.Observable.interval(100);
//ignore everything but error
const error = source
.flatMap(val => {
if(val === 4){
return Rx.Observable.throw(`ERROR AT ${val}`);
}
return Rx.Observable.of(val);
})
.ignoreElements();
//output: "ERROR: ERROR AT 4"
const subscribe = error.subscribe(
val => console.log(`NEXT: ${val}`),
val => console.log(`ERROR: ${val}`),
() => console.log('SECOND COMPLETE!')
);
Additional Resources
- ignoreElements - Official docs
Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/operator/ignoreElements.ts