wishthis/node_modules/rxjs/internal/scheduled/scheduleIterable.js

48 lines
1.5 KiB
JavaScript
Raw Normal View History

2022-01-21 08:28:41 +00:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Observable_1 = require("../Observable");
2022-05-29 09:24:36 +00:00
var Subscription_1 = require("../Subscription");
2022-01-21 08:28:41 +00:00
var iterator_1 = require("../symbol/iterator");
function scheduleIterable(input, scheduler) {
2022-05-29 09:24:36 +00:00
if (!input) {
throw new Error('Iterable cannot be null');
}
2022-01-21 08:28:41 +00:00
return new Observable_1.Observable(function (subscriber) {
2022-05-29 09:24:36 +00:00
var sub = new Subscription_1.Subscription();
2022-01-21 08:28:41 +00:00
var iterator;
2022-05-29 09:24:36 +00:00
sub.add(function () {
if (iterator && typeof iterator.return === 'function') {
iterator.return();
}
});
sub.add(scheduler.schedule(function () {
2022-01-21 08:28:41 +00:00
iterator = input[iterator_1.iterator]();
2022-05-29 09:24:36 +00:00
sub.add(scheduler.schedule(function () {
if (subscriber.closed) {
return;
}
2022-01-21 08:28:41 +00:00
var value;
var done;
try {
2022-05-29 09:24:36 +00:00
var result = iterator.next();
value = result.value;
done = result.done;
2022-01-21 08:28:41 +00:00
}
catch (err) {
subscriber.error(err);
return;
}
if (done) {
subscriber.complete();
}
else {
subscriber.next(value);
2022-05-29 09:24:36 +00:00
this.schedule();
2022-01-21 08:28:41 +00:00
}
2022-05-29 09:24:36 +00:00
}));
}));
return sub;
2022-01-21 08:28:41 +00:00
});
}
exports.scheduleIterable = scheduleIterable;
//# sourceMappingURL=scheduleIterable.js.map