Is there reliable solution to get a snapshot of values currently buffered in ReplaySubject?
I came up with something like this, but not sure how reliable this solution is:
replaySubject.pipe(
takeUntil(timer(10).pipe(take(1)))
)
The timer factor above seems wrong to me as I have no warranty if all values have been emitted properly within given time (this applies to replay subjects with a lot of values).
I think this can be an approach:
StackBlitz demo.
The
ReplaySubject
, when a new subscriber is registered, it will emit its values synchronously:for this reason, we're using
buffer(timer(0))
: by the time thebuffer
's notifier(timer(0)
) emits, the values will have already been added in thebuffer
's array. So, it will be able to emit all theReplaySubject
's accumulated values.