Async Subject - RXJS
In this tutorial, we will learn about the Async Subject of RXJS.
Async Subject
A variant of Subject that only emits a value when it completes. It will emit its latest value to all its observers on completion.
import { AsyncSubject} from 'rxjs';
mySubject = new AsyncSubject();
this.mySubject .next(1);
this.mySubject .next(2);
this.mySubject .next(3);
this.mySubject .next(4);
setTimeout(() => {
this.mySubject.complete();
}, 1000);
mySubject.subscribe(res => {
console.log(res);
});
It will Output:
4