Path: blob/master/node_modules/asynckit/lib/readable_asynckit.js
1126 views
var streamify = require('./streamify.js')1, defer = require('./defer.js')2;34// API5module.exports = ReadableAsyncKit;67/**8* Base constructor for all streams9* used to hold properties/methods10*/11function ReadableAsyncKit()12{13ReadableAsyncKit.super_.apply(this, arguments);1415// list of active jobs16this.jobs = {};1718// add stream methods19this.destroy = destroy;20this._start = _start;21this._read = _read;22}2324/**25* Destroys readable stream,26* by aborting outstanding jobs27*28* @returns {void}29*/30function destroy()31{32if (this.destroyed)33{34return;35}3637this.destroyed = true;3839if (typeof this.terminator == 'function')40{41this.terminator();42}43}4445/**46* Starts provided jobs in async manner47*48* @private49*/50function _start()51{52// first argument – runner function53var runner = arguments[0]54// take away first argument55, args = Array.prototype.slice.call(arguments, 1)56// second argument - input data57, input = args[0]58// last argument - result callback59, endCb = streamify.callback.call(this, args[args.length - 1])60;6162args[args.length - 1] = endCb;63// third argument - iterator64args[1] = streamify.iterator.call(this, args[1]);6566// allow time for proper setup67defer(function()68{69if (!this.destroyed)70{71this.terminator = runner.apply(null, args);72}73else74{75endCb(null, Array.isArray(input) ? [] : {});76}77}.bind(this));78}798081/**82* Implement _read to comply with Readable streams83* Doesn't really make sense for flowing object mode84*85* @private86*/87function _read()88{8990}919293