wishthis/node_modules/rxjs/_esm2015/internal/util/subscribeToIterable.js

31 lines
831 B
JavaScript
Raw Normal View History

2022-01-21 08:28:41 +00:00
import { iterator as Symbol_iterator } from '../symbol/iterator';
export const subscribeToIterable = (iterable) => (subscriber) => {
const iterator = iterable[Symbol_iterator]();
do {
let item;
try {
item = iterator.next();
}
catch (err) {
subscriber.error(err);
return subscriber;
}
if (item.done) {
subscriber.complete();
break;
}
subscriber.next(item.value);
if (subscriber.closed) {
break;
}
} while (true);
if (typeof iterator.return === 'function') {
subscriber.add(() => {
if (iterator.return) {
iterator.return();
}
});
}
return subscriber;
};
//# sourceMappingURL=subscribeToIterable.js.map