The AsyncSubject
is a type of subject in RxJS library that only emits the last value from the source observable to its subscribers. It will wait until the source observable completes and then it will emit the last value to all subscribers.
Here is an example of how to use the AsyncSubject
:
index.tsx479 chars22 lines
In the example above, we imported the AsyncSubject
class from the RxJS library, then instantiated an AsyncSubject
object. After that, we subscribed to the subject to receive emitted values. We then emitted two values using the next()
method and finally called the complete()
method to inform the AsyncSubject
that we are done emitting values.
The output shows that only the last value (2) was emitted to the subscriber after the AsyncSubject
completed.
gistlibby LogSnag