Last change
on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
831 bytes
|
Line | |
---|
1 | import { iterator as Symbol_iterator } from '../symbol/iterator';
|
---|
2 | export const subscribeToIterable = (iterable) => (subscriber) => {
|
---|
3 | const iterator = iterable[Symbol_iterator]();
|
---|
4 | do {
|
---|
5 | let item;
|
---|
6 | try {
|
---|
7 | item = iterator.next();
|
---|
8 | }
|
---|
9 | catch (err) {
|
---|
10 | subscriber.error(err);
|
---|
11 | return subscriber;
|
---|
12 | }
|
---|
13 | if (item.done) {
|
---|
14 | subscriber.complete();
|
---|
15 | break;
|
---|
16 | }
|
---|
17 | subscriber.next(item.value);
|
---|
18 | if (subscriber.closed) {
|
---|
19 | break;
|
---|
20 | }
|
---|
21 | } while (true);
|
---|
22 | if (typeof iterator.return === 'function') {
|
---|
23 | subscriber.add(() => {
|
---|
24 | if (iterator.return) {
|
---|
25 | iterator.return();
|
---|
26 | }
|
---|
27 | });
|
---|
28 | }
|
---|
29 | return subscriber;
|
---|
30 | };
|
---|
31 | //# sourceMappingURL=subscribeToIterable.js.map |
---|
Note:
See
TracBrowser
for help on using the repository browser.