tra-analysis/website/functions/node_modules/split-array-stream/index.js

23 lines
412 B
JavaScript
Raw Normal View History

2019-01-06 19:14:45 +00:00
'use strict';
var async = require('async');
var ended = require('is-stream-ended');
module.exports = function (array, stream, callback) {
var arr = [].slice.call(array);
async.whilst(
function () {
return !ended(stream) && arr.length > 0;
},
function (next) {
stream.push(arr.shift());
setImmediate(next);
},
function () {
callback(ended(stream));
});
};