Your first subscriber subscribes to a
, since refCount
first activates the stream, if there is at least one subscriber (who is not, because not b
, but a
signed), this is not active until your last loc.
a = new Rx.Subject(); b = a.publishReplay(1).refCount(); b.subscribe(function(x){console.log('timely subscriber:',x)}); a.next(1); b.subscribe(function(x){console.log('late subscriber:',x)});
<script src="https://unpkg.com/rxjs/bundles/Rx.min.js"></script>
source share