pnpm
Version:
Fast, disk space efficient package manager
31 lines (23 loc) • 765 B
JavaScript
/** @license MIT License (c) copyright 2010-2016 original author or authors */
/** @author Brian Cavalier */
/** @author John Hann */
import Stream from '../Stream'
import { getIterator } from '../iterable'
import PropagateTask from '../scheduler/PropagateTask'
export function fromIterable (iterable) {
return new Stream(new IterableSource(iterable))
}
function IterableSource (iterable) {
this.iterable = iterable
}
IterableSource.prototype.run = function (sink, scheduler) {
return scheduler.asap(new PropagateTask(runProducer, 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)
}