次のようなコードスニペットがあります
var videosNeedFix = Rx.Observable.fromArray(JSON.parse(fs.readFileSync("videoEntries.json"))).share();
videosNeedFix.count().subscribe(function(count){ //subscrption A
console.log(count + " in total");
});
videosNeedFix.subscribe(function(videoEntry){ //subscription B
console.log(videoEntry.id, videoEntry.name, videoEntry.customFields);
});
videoEntries.json は、videoEntry オブジェクトの JSON シリアル化配列です。サブスクリプション A とサブスクリプション B の両方が、videosNeedFix オブザーバブルによって発行されたデータを受け取ることを期待しています。
ただし、コンソール ログによると、サブスクリプション A のみがデータを受信し、サブスクリプション B は受信しません。2 つのサブスクリプションを作成する順序を入れ替えると、subscriptionB だけがデータを参照できます。オブザーバブルが最初のサブスクリプションにのみデータを発行するのはなぜですか?