diff --git a/src/util/subscribeToResult.ts b/src/util/subscribeToResult.ts index 9493a3f2a6..a65023607b 100644 --- a/src/util/subscribeToResult.ts +++ b/src/util/subscribeToResult.ts @@ -56,19 +56,22 @@ export function subscribeToResult(outerSubscriber: OuterSubscriber, }); return destination; } else if (typeof result[$$iterator] === 'function') { - for (let item of result) { - destination.next(item); + const iterator = result[$$iterator](); + do { + let item = iterator.next(); + if (item.done) { + destination.complete(); + break; + } + destination.next(item.value); if (destination.closed) { break; } - } - if (!destination.closed) { - destination.complete(); - } + } while (true); } else if (typeof result[$$observable] === 'function') { const obs = result[$$observable](); if (typeof obs.subscribe !== 'function') { - destination.error('invalid observable'); + destination.error(new Error('invalid observable')); } else { return obs.subscribe(new InnerSubscriber(outerSubscriber, outerValue, outerIndex)); }