MDK
MDK

Reputation: 505

Stop hot Observable from sharing value after complete

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.

Upvotes: 1

Views: 1005

Answers (1)

Steve Holgado
Steve Holgado

Reputation: 12071

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.

Upvotes: 3

Related Questions