Stop hot Observable from sharing value after complete

Viewed 280

I have a hot Observable that I'm using shareReplay(1) to Multicast, but if the Observable is complete and its subscribed to it emits the last value. I need it to not emit anything.

1 Answers

Instead of shareReplay(1), you should be able to use this instead:

share({
  connector: () => new ReplaySubject(1),
  resetOnError: true,
  resetOnComplete: true,
  resetOnRefCountZero: false
})

The resetOnRefCountZero: false just ensures that you can still subscribe again (and receive the shared value) even if all subscribers have unsubscribed at any point.

Note: resetOnError and resetOnComplete default to "true" in the case anyway, but I have added for clarity.

Related