Skip to content

Commit

Permalink
fix(subscribeToResult): update subscription to iterables
Browse files Browse the repository at this point in the history
- update iteration logic same as IteraterObservable, can actually iterate objects
  • Loading branch information
kwonoj committed Aug 1, 2016
1 parent c03dabd commit 5d6339a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/util/subscribeToResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,22 @@ export function subscribeToResult<T>(outerSubscriber: OuterSubscriber<any, any>,
});
return destination;
} else if (typeof result[$$iterator] === 'function') {
for (let item of <any>result) {
destination.next(<any>item);
const iterator = <any>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));
}
Expand Down

0 comments on commit 5d6339a

Please sign in to comment.