diff --git a/aio/content/examples/observables/src/multicasting.ts b/aio/content/examples/observables/src/multicasting.ts index 449f7b73c7..e8275842f0 100644 --- a/aio/content/examples/observables/src/multicasting.ts +++ b/aio/content/examples/observables/src/multicasting.ts @@ -15,7 +15,7 @@ function sequenceSubscriber(observer) { if (idx === arr.length - 1) { observer.complete(); } else { - doSequence(arr, idx++); + doSequence(arr, ++idx); } }, 1000); } @@ -95,7 +95,7 @@ function multicastSequenceSubscriber() { }, complete() { // Notify all complete callbacks - observers.forEach(obs => obs.complete()); + observers.slice(0).forEach(obs => obs.complete()); } }, seq, 0); } @@ -121,13 +121,13 @@ function doSequence(observer, arr, idx) { if (idx === arr.length - 1) { observer.complete(); } else { - doSequence(observer, arr, idx++); + doSequence(observer, arr, ++idx); } }, 1000); } // Create a new Observable that will deliver the above sequence -const multicastSequence = new Observable(multicastSequenceSubscriber); +const multicastSequence = new Observable(multicastSequenceSubscriber()); // Subscribe starts the clock, and begins to emit after 1 second multicastSequence.subscribe({