43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
|
'use strict';
|
||
|
|
||
|
Object.defineProperty(exports, "__esModule", {
|
||
|
value: true
|
||
|
});
|
||
|
exports.fromIterable = fromIterable;
|
||
|
|
||
|
var _Stream = require('../Stream');
|
||
|
|
||
|
var _Stream2 = _interopRequireDefault(_Stream);
|
||
|
|
||
|
var _iterable = require('../iterable');
|
||
|
|
||
|
var _PropagateTask = require('../scheduler/PropagateTask');
|
||
|
|
||
|
var _PropagateTask2 = _interopRequireDefault(_PropagateTask);
|
||
|
|
||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||
|
|
||
|
function fromIterable(iterable) {
|
||
|
return new _Stream2.default(new IterableSource(iterable));
|
||
|
} /** @license MIT License (c) copyright 2010-2016 original author or authors */
|
||
|
/** @author Brian Cavalier */
|
||
|
/** @author John Hann */
|
||
|
|
||
|
function IterableSource(iterable) {
|
||
|
this.iterable = iterable;
|
||
|
}
|
||
|
|
||
|
IterableSource.prototype.run = function (sink, scheduler) {
|
||
|
return scheduler.asap(new _PropagateTask2.default(runProducer, (0, _iterable.getIterator)(this.iterable), sink));
|
||
|
};
|
||
|
|
||
|
function runProducer(t, iterator, sink) {
|
||
|
var r = iterator.next();
|
||
|
|
||
|
while (!r.done && this.active) {
|
||
|
sink.event(t, r.value);
|
||
|
r = iterator.next();
|
||
|
}
|
||
|
|
||
|
sink.end(t, r.value);
|
||
|
}
|