The refCount operator is discussed in this article. It explains the necessity of adding delay(0)
to prevent unsubscription of observable A: import { Observable } from "rxjs/Observable";
const source = Observable.defer(() => Observable.of(
Math.floor(Math.random() * 100)
)).delay(0);
Is 0
always sufficient? Simply put, does setting it to zero ensure that the notification will be delayed until all m.subscribe()
statements are executed, especially if they immediately follow the multicast
statement as shown:
const m = source.multicast(() => new Subject<number>()).refCount();
m.subscribe(observer("a"));
m.subscribe(observer("b"));
In this scenario, only observers a
and b
are subscribed. If a million more observers were added after the multicast statement, would using delay(0)
still guarantee that all subscriptions are completed before the first source notification occurs?