Comparing version 0.0.2 to 0.1.0
@@ -15,3 +15,3 @@ /** | ||
this.use( express.bodyParser() ); | ||
this.use( express.json() ); | ||
this.use( this.router ); | ||
@@ -18,0 +18,0 @@ this.use( express.errorHandler() ); |
@@ -39,30 +39,31 @@ /** | ||
// Set instance properties | ||
this.id = Math.random().toString( 36 ).substring( 7 ); | ||
this.tasks = tasks; | ||
this.callback = arguments[1] instanceof Function ? arguments[1] : function defaultCallback() {}; | ||
this.settings = auto.extend( {}, auto.defaults, arguments.length === 3 ? settings : 'function' !== typeof callback ? callback : {} ); | ||
this.response = {}; | ||
this.listeners = []; | ||
this._meta = { started: new Date().getTime(), timeout: new Date().getTime() + this.settings.timeout }; | ||
this.error = null; | ||
this.keys = Object.keys( this.tasks ); | ||
self.id = Math.random().toString( 36 ).substring( 7 ); | ||
self.tasks = tasks; | ||
self.callback = arguments[1] instanceof Function ? arguments[1] : function defaultCallback() {}; | ||
self.settings = auto.extend( {}, auto.defaults, arguments.length === 3 ? settings : 'function' !== typeof callback ? callback : {} ); | ||
self.response = {}; | ||
self.listeners = []; | ||
self._meta = { started: new Date().getTime(), timeout: new Date().getTime() + self.settings.timeout }; | ||
self.error = null; | ||
self.keys = Object.keys( self.tasks ); | ||
// Extend this with Event Emitter | ||
auto.emitter.mixin( this ); | ||
auto.emitter.mixin( self ); | ||
// Ensure there are tasks | ||
if( !this.keys.length ) { | ||
return callback( null ); | ||
if( !self.keys.length ) { | ||
process.nextTick( function() { self.emit( 'complete', null, {} ); }); | ||
return self.callback( null ); | ||
} | ||
// Add to running queue | ||
auto.active[ this.id ] = this; | ||
auto.active[ self.id ] = self; | ||
// Add final listener | ||
self.addListener( this.onComplete ); | ||
self.addListener( self.onComplete ); | ||
// Iterate through keys | ||
self.each( this.keys, this.taskIterator ); | ||
self.each( self.keys, self.taskIterator ); | ||
return this; | ||
return self; | ||
@@ -343,2 +344,9 @@ } | ||
Object.defineProperties( module.exports = auto, { | ||
createBatch: { | ||
value: function createBatch( options ) { | ||
return require( './auto.batch' ).create( options ); | ||
}, | ||
writable: true, | ||
enumerable: false | ||
}, | ||
middleware: { | ||
@@ -345,0 +353,0 @@ /** |
{ | ||
"name": "auto", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "Asynchronous task runner for Node.js", | ||
"main": "index", | ||
"keywords" : [ | ||
"keywords": [ | ||
"express", | ||
@@ -12,3 +12,3 @@ "async", | ||
], | ||
"copyright" : "Copyright (c) 2013 Usability Dynamics, Inc.", | ||
"copyright": "Copyright (c) 2013 Usability Dynamics, Inc.", | ||
"engines": [ | ||
@@ -40,9 +40,12 @@ "node >=0.8.0", | ||
"type": "git", | ||
"url": "https://github.com/UsabilityDynamics/auto" | ||
"url": "https://github.com/UsabilityDynamics/node-auto" | ||
}, | ||
"dependencies": { | ||
"object-emitter": "0.0.2", | ||
"extend": "1.1.3" | ||
"extend": "1.1.3", | ||
"foreign-key": "~0.1.0", | ||
"async": "~0.2.9" | ||
}, | ||
"devDependencies": { | ||
"faker": "*", | ||
"request": "*", | ||
@@ -52,2 +55,2 @@ "express": "*", | ||
} | ||
} | ||
} |
@@ -8,33 +8,33 @@ Asynchronous task runner for Node.js | ||
```javascript | ||
auto({ | ||
auto({ | ||
// Get data, simulation as asynchornous operation | ||
get_data: [ function get_data( next, report ) { | ||
// Get data, simulation as asynchornous operation | ||
get_data: [ function get_data( next, report ) { | ||
next( null, { | ||
name: 'Eric Flatley', | ||
username: 'Arnoldo_Lubowitz', | ||
email: 'Tyshawn@emie.biz', | ||
phone: '917.531.3079 x06115', | ||
website: 'donald.io' | ||
}); | ||
next( null, { | ||
name: 'Eric Flatley', | ||
username: 'Arnoldo_Lubowitz', | ||
email: 'Tyshawn@emie.biz', | ||
phone: '917.531.3079 x06115', | ||
website: 'donald.io' | ||
}); | ||
}], | ||
}], | ||
// Create folder, which is an asynchronous operation | ||
make_folder: [ 'get_data', function make_folder( next, report ) { | ||
setTimeout( function() { next( null, 'folder created' ); }, 100 ) | ||
}], | ||
// Create folder, which is an asynchronous operation | ||
make_folder: [ 'get_data', function make_folder( next, report ) { | ||
setTimeout( function() { next( null, 'folder created' ); }, 100 ) | ||
}], | ||
// Write file once we have the data and folder is created | ||
write_file: ['get_data', 'make_folder', function write_file( next, report ) { | ||
setTimeout( function() { next( null, 'folder created' ); }, 200 ) | ||
}], | ||
// Write file once we have the data and folder is created | ||
write_file: ['get_data', 'make_folder', function write_file( next, report ) { | ||
setTimeout( function() { next( null, 'folder created' ); }, 200 ) | ||
}], | ||
// Email Link once file is written | ||
email_link: ['write_file', function email_link( next, report ) { | ||
next( null, 'email sent' ); | ||
}] | ||
// Email Link once file is written | ||
email_link: ['write_file', function email_link( next, report ) { | ||
next( null, 'email sent' ); | ||
}] | ||
}).once( 'complete', console.log ) | ||
}).once( 'complete', console.log ) | ||
``` | ||
@@ -46,3 +46,3 @@ | ||
```javascript | ||
app.get( '/test/:id', auto.middleware( tasks ); | ||
app.get( '/test/:id', auto.middleware( tasks ); | ||
``` | ||
@@ -49,0 +49,0 @@ |
@@ -41,3 +41,3 @@ { | ||
"file": "lib/auto.js", | ||
"line": 70, | ||
"line": 71, | ||
"description": "Instance Properties.", | ||
@@ -49,3 +49,3 @@ "class": "", | ||
"file": "lib/auto.js", | ||
"line": 91, | ||
"line": 92, | ||
"description": "Task Callback", | ||
@@ -66,3 +66,3 @@ "todo": [ | ||
"file": "lib/auto.js", | ||
"line": 140, | ||
"line": 141, | ||
"description": "Ready to Process a Step", | ||
@@ -81,3 +81,3 @@ "todo": [ | ||
"file": "lib/auto.js", | ||
"line": 215, | ||
"line": 216, | ||
"description": "Remove Listener from Queue", | ||
@@ -101,3 +101,3 @@ "itemtype": "method", | ||
"file": "lib/auto.js", | ||
"line": 235, | ||
"line": 236, | ||
"description": "Run Method on next tick", | ||
@@ -121,3 +121,3 @@ "itemtype": "method", | ||
"file": "lib/auto.js", | ||
"line": 256, | ||
"line": 257, | ||
"description": "Array Iterator", | ||
@@ -145,3 +145,3 @@ "itemtype": "method", | ||
"file": "lib/auto.js", | ||
"line": 273, | ||
"line": 274, | ||
"description": "Array Reduce", | ||
@@ -173,3 +173,3 @@ "itemtype": "method", | ||
"file": "lib/auto.js", | ||
"line": 299, | ||
"line": 300, | ||
"description": "Add Listener to Queue in context", | ||
@@ -193,3 +193,3 @@ "itemtype": "method", | ||
"file": "lib/auto.js", | ||
"line": 315, | ||
"line": 316, | ||
"description": "Single Step Complete", | ||
@@ -213,3 +213,3 @@ "itemtype": "method", | ||
"file": "lib/auto.js", | ||
"line": 337, | ||
"line": 338, | ||
"description": "Constructor Properties", | ||
@@ -221,3 +221,3 @@ "class": "", | ||
"file": "lib/auto.js", | ||
"line": 343, | ||
"line": 344, | ||
"params": [ | ||
@@ -252,41 +252,41 @@ { | ||
"message": "replacing incorrect tag: returns with return", | ||
"line": " lib/auto.js:140" | ||
"line": " lib/auto.js:141" | ||
}, | ||
{ | ||
"message": "replacing incorrect tag: returns with return", | ||
"line": " lib/auto.js:235" | ||
"line": " lib/auto.js:236" | ||
}, | ||
{ | ||
"message": "replacing incorrect tag: returns with return", | ||
"line": " lib/auto.js:256" | ||
"line": " lib/auto.js:257" | ||
}, | ||
{ | ||
"message": "replacing incorrect tag: returns with return", | ||
"line": " lib/auto.js:273" | ||
"line": " lib/auto.js:274" | ||
}, | ||
{ | ||
"message": "replacing incorrect tag: returns with return", | ||
"line": " lib/auto.js:343" | ||
"line": " lib/auto.js:344" | ||
}, | ||
{ | ||
"message": "Missing item type\nInstance Properties.", | ||
"line": " lib/auto.js:70" | ||
"line": " lib/auto.js:71" | ||
}, | ||
{ | ||
"message": "Missing item type\nTask Callback", | ||
"line": " lib/auto.js:91" | ||
"line": " lib/auto.js:92" | ||
}, | ||
{ | ||
"message": "Missing item type\nReady to Process a Step", | ||
"line": " lib/auto.js:140" | ||
"line": " lib/auto.js:141" | ||
}, | ||
{ | ||
"message": "Missing item type\nConstructor Properties", | ||
"line": " lib/auto.js:337" | ||
"line": " lib/auto.js:338" | ||
}, | ||
{ | ||
"message": "Missing item type", | ||
"line": " lib/auto.js:343" | ||
"line": " lib/auto.js:344" | ||
} | ||
] | ||
} |
@@ -28,71 +28,72 @@ /* automatically generated by JSCoverage - do not edit */ | ||
_$jscoverage['auto.js'][54] = 0; | ||
_$jscoverage['auto.js'][58] = 0; | ||
_$jscoverage['auto.js'][61] = 0; | ||
_$jscoverage['auto.js'][64] = 0; | ||
_$jscoverage['auto.js'][66] = 0; | ||
_$jscoverage['auto.js'][74] = 0; | ||
_$jscoverage['auto.js'][78] = 0; | ||
_$jscoverage['auto.js'][55] = 0; | ||
_$jscoverage['auto.js'][59] = 0; | ||
_$jscoverage['auto.js'][62] = 0; | ||
_$jscoverage['auto.js'][65] = 0; | ||
_$jscoverage['auto.js'][67] = 0; | ||
_$jscoverage['auto.js'][75] = 0; | ||
_$jscoverage['auto.js'][79] = 0; | ||
_$jscoverage['auto.js'][80] = 0; | ||
_$jscoverage['auto.js'][83] = 0; | ||
_$jscoverage['auto.js'][97] = 0; | ||
_$jscoverage['auto.js'][100] = 0; | ||
_$jscoverage['auto.js'][102] = 0; | ||
_$jscoverage['auto.js'][81] = 0; | ||
_$jscoverage['auto.js'][84] = 0; | ||
_$jscoverage['auto.js'][98] = 0; | ||
_$jscoverage['auto.js'][101] = 0; | ||
_$jscoverage['auto.js'][103] = 0; | ||
_$jscoverage['auto.js'][106] = 0; | ||
_$jscoverage['auto.js'][104] = 0; | ||
_$jscoverage['auto.js'][107] = 0; | ||
_$jscoverage['auto.js'][109] = 0; | ||
_$jscoverage['auto.js'][108] = 0; | ||
_$jscoverage['auto.js'][110] = 0; | ||
_$jscoverage['auto.js'][113] = 0; | ||
_$jscoverage['auto.js'][116] = 0; | ||
_$jscoverage['auto.js'][111] = 0; | ||
_$jscoverage['auto.js'][114] = 0; | ||
_$jscoverage['auto.js'][117] = 0; | ||
_$jscoverage['auto.js'][120] = 0; | ||
_$jscoverage['auto.js'][123] = 0; | ||
_$jscoverage['auto.js'][126] = 0; | ||
_$jscoverage['auto.js'][131] = 0; | ||
_$jscoverage['auto.js'][134] = 0; | ||
_$jscoverage['auto.js'][138] = 0; | ||
_$jscoverage['auto.js'][146] = 0; | ||
_$jscoverage['auto.js'][149] = 0; | ||
_$jscoverage['auto.js'][118] = 0; | ||
_$jscoverage['auto.js'][121] = 0; | ||
_$jscoverage['auto.js'][124] = 0; | ||
_$jscoverage['auto.js'][127] = 0; | ||
_$jscoverage['auto.js'][132] = 0; | ||
_$jscoverage['auto.js'][135] = 0; | ||
_$jscoverage['auto.js'][139] = 0; | ||
_$jscoverage['auto.js'][147] = 0; | ||
_$jscoverage['auto.js'][150] = 0; | ||
_$jscoverage['auto.js'][154] = 0; | ||
_$jscoverage['auto.js'][156] = 0; | ||
_$jscoverage['auto.js'][158] = 0; | ||
_$jscoverage['auto.js'][161] = 0; | ||
_$jscoverage['auto.js'][163] = 0; | ||
_$jscoverage['auto.js'][168] = 0; | ||
_$jscoverage['auto.js'][170] = 0; | ||
_$jscoverage['auto.js'][151] = 0; | ||
_$jscoverage['auto.js'][155] = 0; | ||
_$jscoverage['auto.js'][157] = 0; | ||
_$jscoverage['auto.js'][159] = 0; | ||
_$jscoverage['auto.js'][162] = 0; | ||
_$jscoverage['auto.js'][164] = 0; | ||
_$jscoverage['auto.js'][169] = 0; | ||
_$jscoverage['auto.js'][171] = 0; | ||
_$jscoverage['auto.js'][172] = 0; | ||
_$jscoverage['auto.js'][187] = 0; | ||
_$jscoverage['auto.js'][173] = 0; | ||
_$jscoverage['auto.js'][188] = 0; | ||
_$jscoverage['auto.js'][192] = 0; | ||
_$jscoverage['auto.js'][189] = 0; | ||
_$jscoverage['auto.js'][193] = 0; | ||
_$jscoverage['auto.js'][197] = 0; | ||
_$jscoverage['auto.js'][194] = 0; | ||
_$jscoverage['auto.js'][198] = 0; | ||
_$jscoverage['auto.js'][201] = 0; | ||
_$jscoverage['auto.js'][204] = 0; | ||
_$jscoverage['auto.js'][207] = 0; | ||
_$jscoverage['auto.js'][225] = 0; | ||
_$jscoverage['auto.js'][199] = 0; | ||
_$jscoverage['auto.js'][202] = 0; | ||
_$jscoverage['auto.js'][205] = 0; | ||
_$jscoverage['auto.js'][208] = 0; | ||
_$jscoverage['auto.js'][226] = 0; | ||
_$jscoverage['auto.js'][244] = 0; | ||
_$jscoverage['auto.js'][227] = 0; | ||
_$jscoverage['auto.js'][245] = 0; | ||
_$jscoverage['auto.js'][248] = 0; | ||
_$jscoverage['auto.js'][265] = 0; | ||
_$jscoverage['auto.js'][246] = 0; | ||
_$jscoverage['auto.js'][249] = 0; | ||
_$jscoverage['auto.js'][266] = 0; | ||
_$jscoverage['auto.js'][284] = 0; | ||
_$jscoverage['auto.js'][267] = 0; | ||
_$jscoverage['auto.js'][285] = 0; | ||
_$jscoverage['auto.js'][288] = 0; | ||
_$jscoverage['auto.js'][286] = 0; | ||
_$jscoverage['auto.js'][289] = 0; | ||
_$jscoverage['auto.js'][292] = 0; | ||
_$jscoverage['auto.js'][308] = 0; | ||
_$jscoverage['auto.js'][326] = 0; | ||
_$jscoverage['auto.js'][290] = 0; | ||
_$jscoverage['auto.js'][293] = 0; | ||
_$jscoverage['auto.js'][309] = 0; | ||
_$jscoverage['auto.js'][327] = 0; | ||
_$jscoverage['auto.js'][341] = 0; | ||
_$jscoverage['auto.js'][352] = 0; | ||
_$jscoverage['auto.js'][354] = 0; | ||
_$jscoverage['auto.js'][356] = 0; | ||
_$jscoverage['auto.js'][328] = 0; | ||
_$jscoverage['auto.js'][342] = 0; | ||
_$jscoverage['auto.js'][353] = 0; | ||
_$jscoverage['auto.js'][355] = 0; | ||
_$jscoverage['auto.js'][357] = 0; | ||
_$jscoverage['auto.js'][360] = 0; | ||
_$jscoverage['auto.js'][358] = 0; | ||
_$jscoverage['auto.js'][361] = 0; | ||
_$jscoverage['auto.js'][362] = 0; | ||
} | ||
@@ -127,75 +128,80 @@ _$jscoverage['auto.js'][12]++; | ||
_$jscoverage['auto.js'][39]++; | ||
this.id = Math.random().toString(36).substring(7); | ||
self.id = Math.random().toString(36).substring(7); | ||
_$jscoverage['auto.js'][40]++; | ||
this.tasks = tasks; | ||
self.tasks = tasks; | ||
_$jscoverage['auto.js'][41]++; | ||
this.callback = arguments[1] instanceof Function? arguments[1]: (function defaultCallback() { | ||
self.callback = arguments[1] instanceof Function? arguments[1]: (function defaultCallback() { | ||
}); | ||
_$jscoverage['auto.js'][42]++; | ||
this.settings = auto.extend({}, auto.defaults, arguments.length === 3? settings: "function" !== typeof callback? callback: {}); | ||
self.settings = auto.extend({}, auto.defaults, arguments.length === 3? settings: "function" !== typeof callback? callback: {}); | ||
_$jscoverage['auto.js'][43]++; | ||
this.response = {}; | ||
self.response = {}; | ||
_$jscoverage['auto.js'][44]++; | ||
this.listeners = []; | ||
self.listeners = []; | ||
_$jscoverage['auto.js'][45]++; | ||
this._meta = {started: new Date().getTime(), timeout: new Date().getTime() + this.settings.timeout}; | ||
self._meta = {started: new Date().getTime(), timeout: new Date().getTime() + self.settings.timeout}; | ||
_$jscoverage['auto.js'][46]++; | ||
this.error = null; | ||
self.error = null; | ||
_$jscoverage['auto.js'][47]++; | ||
this.keys = Object.keys(this.tasks); | ||
self.keys = Object.keys(self.tasks); | ||
_$jscoverage['auto.js'][50]++; | ||
auto.emitter.mixin(this); | ||
auto.emitter.mixin(self); | ||
_$jscoverage['auto.js'][53]++; | ||
if (! this.keys.length) { | ||
if (! self.keys.length) { | ||
_$jscoverage['auto.js'][54]++; | ||
return callback(null); | ||
process.nextTick((function () { | ||
_$jscoverage['auto.js'][54]++; | ||
self.emit("complete", null, {}); | ||
})); | ||
_$jscoverage['auto.js'][55]++; | ||
return self.callback(null); | ||
} | ||
_$jscoverage['auto.js'][58]++; | ||
auto.active[this.id] = this; | ||
_$jscoverage['auto.js'][61]++; | ||
self.addListener(this.onComplete); | ||
_$jscoverage['auto.js'][64]++; | ||
self.each(this.keys, this.taskIterator); | ||
_$jscoverage['auto.js'][66]++; | ||
return this; | ||
_$jscoverage['auto.js'][59]++; | ||
auto.active[self.id] = self; | ||
_$jscoverage['auto.js'][62]++; | ||
self.addListener(self.onComplete); | ||
_$jscoverage['auto.js'][65]++; | ||
self.each(self.keys, self.taskIterator); | ||
_$jscoverage['auto.js'][67]++; | ||
return self; | ||
} | ||
_$jscoverage['auto.js'][74]++; | ||
_$jscoverage['auto.js'][75]++; | ||
Object.defineProperties(auto.prototype, {taskIterator: {value: (function taskIterator(key) { | ||
_$jscoverage['auto.js'][78]++; | ||
_$jscoverage['auto.js'][79]++; | ||
var self = this; | ||
_$jscoverage['auto.js'][79]++; | ||
_$jscoverage['auto.js'][80]++; | ||
var task = this.tasks[key] instanceof Function? [this.tasks[key]]: this.tasks[key]; | ||
_$jscoverage['auto.js'][80]++; | ||
_$jscoverage['auto.js'][81]++; | ||
var requires = task.slice(0, Math.abs(task.length - 1)) || []; | ||
_$jscoverage['auto.js'][83]++; | ||
_$jscoverage['auto.js'][84]++; | ||
var context = {id: self.id, task: key, requires: requires, response: self.response, tasks: self.tasks}; | ||
_$jscoverage['auto.js'][97]++; | ||
_$jscoverage['auto.js'][98]++; | ||
function taskCallback(error) { | ||
_$jscoverage['auto.js'][100]++; | ||
_$jscoverage['auto.js'][101]++; | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
_$jscoverage['auto.js'][102]++; | ||
_$jscoverage['auto.js'][103]++; | ||
if (args.length <= 1) { | ||
_$jscoverage['auto.js'][103]++; | ||
_$jscoverage['auto.js'][104]++; | ||
args = args[0]; | ||
} | ||
_$jscoverage['auto.js'][106]++; | ||
_$jscoverage['auto.js'][107]++; | ||
if (error && error instanceof Error) { | ||
_$jscoverage['auto.js'][107]++; | ||
_$jscoverage['auto.js'][108]++; | ||
var safeResults = {}; | ||
_$jscoverage['auto.js'][109]++; | ||
_$jscoverage['auto.js'][110]++; | ||
auto.each(Object.keys(self.response), (function (rkey) { | ||
_$jscoverage['auto.js'][110]++; | ||
_$jscoverage['auto.js'][111]++; | ||
safeResults[rkey] = self.response[rkey]; | ||
})); | ||
_$jscoverage['auto.js'][113]++; | ||
_$jscoverage['auto.js'][114]++; | ||
safeResults[key] = args; | ||
_$jscoverage['auto.js'][116]++; | ||
_$jscoverage['auto.js'][117]++; | ||
self.emit("error", error, safeResults); | ||
_$jscoverage['auto.js'][117]++; | ||
_$jscoverage['auto.js'][118]++; | ||
self.emit("complete", error, safeResults); | ||
_$jscoverage['auto.js'][120]++; | ||
_$jscoverage['auto.js'][121]++; | ||
delete auto.active[this.id]; | ||
_$jscoverage['auto.js'][123]++; | ||
_$jscoverage['auto.js'][124]++; | ||
self.callback(error, safeResults); | ||
_$jscoverage['auto.js'][126]++; | ||
_$jscoverage['auto.js'][127]++; | ||
self.callback = (function __fake_callback__() { | ||
@@ -205,37 +211,37 @@ }); | ||
else { | ||
_$jscoverage['auto.js'][131]++; | ||
_$jscoverage['auto.js'][132]++; | ||
self.response[key] = args; | ||
_$jscoverage['auto.js'][134]++; | ||
_$jscoverage['auto.js'][135]++; | ||
self.setImmediate(self.stepComplete.bind(self), key, args); | ||
} | ||
} | ||
_$jscoverage['auto.js'][138]++; | ||
_$jscoverage['auto.js'][139]++; | ||
; | ||
_$jscoverage['auto.js'][146]++; | ||
_$jscoverage['auto.js'][147]++; | ||
function ready() { | ||
_$jscoverage['auto.js'][149]++; | ||
_$jscoverage['auto.js'][150]++; | ||
var magic = self.reduce(requires, (function (a, x) { | ||
_$jscoverage['auto.js'][150]++; | ||
_$jscoverage['auto.js'][151]++; | ||
return (a && self.response.hasOwnProperty(x)); | ||
}), true) && ! self.response.hasOwnProperty(key); | ||
_$jscoverage['auto.js'][154]++; | ||
_$jscoverage['auto.js'][155]++; | ||
self.emit("ready", key, magic); | ||
_$jscoverage['auto.js'][156]++; | ||
_$jscoverage['auto.js'][157]++; | ||
return magic; | ||
} | ||
_$jscoverage['auto.js'][158]++; | ||
_$jscoverage['auto.js'][159]++; | ||
; | ||
_$jscoverage['auto.js'][161]++; | ||
_$jscoverage['auto.js'][162]++; | ||
if (ready()) { | ||
_$jscoverage['auto.js'][163]++; | ||
_$jscoverage['auto.js'][164]++; | ||
task[task.length - 1].bind(context)(taskCallback, self.response, self); | ||
} | ||
else { | ||
_$jscoverage['auto.js'][168]++; | ||
_$jscoverage['auto.js'][169]++; | ||
self.addListener((function listener() { | ||
_$jscoverage['auto.js'][170]++; | ||
_$jscoverage['auto.js'][171]++; | ||
if (ready()) { | ||
_$jscoverage['auto.js'][171]++; | ||
_$jscoverage['auto.js'][172]++; | ||
self.removeListener(listener, key); | ||
_$jscoverage['auto.js'][172]++; | ||
_$jscoverage['auto.js'][173]++; | ||
task[task.length - 1].bind(context)(taskCallback, self.response); | ||
@@ -246,31 +252,31 @@ } | ||
}), writable: false, enumerable: false, configurable: true}, onComplete: {value: (function onComplete() { | ||
_$jscoverage['auto.js'][187]++; | ||
_$jscoverage['auto.js'][188]++; | ||
if (Object.keys(this.response).length !== this.keys.length) { | ||
_$jscoverage['auto.js'][188]++; | ||
_$jscoverage['auto.js'][189]++; | ||
return; | ||
} | ||
_$jscoverage['auto.js'][192]++; | ||
_$jscoverage['auto.js'][193]++; | ||
if (this.callback.name === "Placeholder") { | ||
_$jscoverage['auto.js'][193]++; | ||
_$jscoverage['auto.js'][194]++; | ||
return; | ||
} | ||
_$jscoverage['auto.js'][197]++; | ||
_$jscoverage['auto.js'][198]++; | ||
this.emit("complete", null, this.response); | ||
_$jscoverage['auto.js'][198]++; | ||
_$jscoverage['auto.js'][199]++; | ||
this.emit("success", this.response); | ||
_$jscoverage['auto.js'][201]++; | ||
_$jscoverage['auto.js'][202]++; | ||
this.callback(null, this.response); | ||
_$jscoverage['auto.js'][204]++; | ||
_$jscoverage['auto.js'][205]++; | ||
delete auto.active[this.id]; | ||
_$jscoverage['auto.js'][207]++; | ||
_$jscoverage['auto.js'][208]++; | ||
this.callback = (function Placeholder() { | ||
}); | ||
}), writable: false, enumerable: false, configurable: true}, removeListener: {value: (function removeListener(fn, k) { | ||
_$jscoverage['auto.js'][225]++; | ||
_$jscoverage['auto.js'][226]++; | ||
for (var i = 0; i < this.listeners.length; i += 1) { | ||
_$jscoverage['auto.js'][226]++; | ||
_$jscoverage['auto.js'][227]++; | ||
if (this.listeners[i] === fn) { | ||
_$jscoverage['auto.js'][226]++; | ||
_$jscoverage['auto.js'][227]++; | ||
this.listeners.splice(i, 1); | ||
_$jscoverage['auto.js'][226]++; | ||
_$jscoverage['auto.js'][227]++; | ||
return; | ||
@@ -280,60 +286,60 @@ } | ||
}), writable: false, enumerable: false, configurable: true}, setImmediate: {value: (function setImmediate(fn) { | ||
_$jscoverage['auto.js'][244]++; | ||
_$jscoverage['auto.js'][245]++; | ||
if (process && process.nextTick) { | ||
_$jscoverage['auto.js'][245]++; | ||
_$jscoverage['auto.js'][246]++; | ||
return process.nextTick(fn); | ||
} | ||
_$jscoverage['auto.js'][248]++; | ||
_$jscoverage['auto.js'][249]++; | ||
setTimeout((function () { | ||
_$jscoverage['auto.js'][248]++; | ||
_$jscoverage['auto.js'][249]++; | ||
fn(); | ||
}), 0); | ||
}), writable: false, enumerable: false, configurable: true}, each: {value: (function each(arr, iterator) { | ||
_$jscoverage['auto.js'][265]++; | ||
_$jscoverage['auto.js'][266]++; | ||
if (arr.forEach) { | ||
_$jscoverage['auto.js'][265]++; | ||
_$jscoverage['auto.js'][266]++; | ||
return arr.forEach(iterator.bind(this)); | ||
} | ||
_$jscoverage['auto.js'][266]++; | ||
_$jscoverage['auto.js'][267]++; | ||
for (var i = 0; i < arr.length; i += 1) { | ||
_$jscoverage['auto.js'][266]++; | ||
_$jscoverage['auto.js'][267]++; | ||
iterator.bind(this)(arr[i], i, arr); | ||
} | ||
}), writable: false, enumerable: false, configurable: true}, reduce: {value: (function reduce(arr, iterator, memo) { | ||
_$jscoverage['auto.js'][284]++; | ||
_$jscoverage['auto.js'][285]++; | ||
if (arr.reduce) { | ||
_$jscoverage['auto.js'][285]++; | ||
_$jscoverage['auto.js'][286]++; | ||
return arr.reduce(iterator, memo); | ||
} | ||
_$jscoverage['auto.js'][288]++; | ||
_$jscoverage['auto.js'][289]++; | ||
this.each(arr, (function (x, i, a) { | ||
_$jscoverage['auto.js'][289]++; | ||
_$jscoverage['auto.js'][290]++; | ||
memo = iterator(memo, x, i, a); | ||
})); | ||
_$jscoverage['auto.js'][292]++; | ||
_$jscoverage['auto.js'][293]++; | ||
return memo; | ||
}), writable: false, enumerable: false, configurable: true}, addListener: {value: (function addListener(fn, k) { | ||
_$jscoverage['auto.js'][308]++; | ||
_$jscoverage['auto.js'][309]++; | ||
this.listeners.unshift(fn.bind(this)); | ||
}), writable: false, enumerable: false, configurable: true}, stepComplete: {value: (function stepComplete(k, args) { | ||
_$jscoverage['auto.js'][326]++; | ||
_$jscoverage['auto.js'][327]++; | ||
this.each(this.listeners.slice(0), (function (fn) { | ||
_$jscoverage['auto.js'][327]++; | ||
_$jscoverage['auto.js'][328]++; | ||
fn(); | ||
})); | ||
}), writable: false, enumerable: false, configurable: true}}); | ||
_$jscoverage['auto.js'][341]++; | ||
_$jscoverage['auto.js'][342]++; | ||
Object.defineProperties(module.exports = auto, {middleware: {value: (function middleware(tasks, callback, settings) { | ||
_$jscoverage['auto.js'][352]++; | ||
_$jscoverage['auto.js'][353]++; | ||
return (function middleware(req, res, next) { | ||
_$jscoverage['auto.js'][354]++; | ||
_$jscoverage['auto.js'][355]++; | ||
var instance = auto(tasks, callback, settings); | ||
_$jscoverage['auto.js'][356]++; | ||
_$jscoverage['auto.js'][357]++; | ||
instance.on("success", (function complete(report) { | ||
_$jscoverage['auto.js'][357]++; | ||
_$jscoverage['auto.js'][358]++; | ||
res.send(report); | ||
})); | ||
_$jscoverage['auto.js'][360]++; | ||
_$jscoverage['auto.js'][361]++; | ||
instance.on("error", (function error(error, report) { | ||
_$jscoverage['auto.js'][361]++; | ||
_$jscoverage['auto.js'][362]++; | ||
next(error); | ||
@@ -343,2 +349,2 @@ })); | ||
}), enumerable: true, writable: true, configurable: false}, defaults: {value: {timeout: 5000}, enumerable: true, writable: true, configurable: false}, emitter: {value: require("object-emitter"), writable: true, enumerable: false}, extend: {value: require("extend"), enumerable: false, writable: true}, active: {value: {}, enumerable: true, configurable: false, writable: true}}); | ||
_$jscoverage['auto.js'].source = ["/**"," * auto Module"," *"," * -"," *"," * @module auto"," * @constructor"," * @author potanin@UD"," * @date 8/5/13"," * @type {Object}"," */","function auto( tasks, callback, settings ) {",""," // Ensure always using new instance of auto"," if( !( this instanceof auto ) ) {",""," if( arguments.length === 0 ) {"," return {};"," }",""," if( arguments.length === 1 ) {"," return new auto( tasks );"," }",""," if( arguments.length === 2 ) {"," return new auto( tasks, callback );"," }",""," if( arguments.length === 3 ) {"," return new auto( tasks, callback, settings );"," }",""," }",""," // Set private properties"," var self = this;",""," // Set instance properties"," this.id = Math.random().toString( 36 ).substring( 7 );"," this.tasks = tasks;"," this.callback = arguments[1] instanceof Function ? arguments[1] : function defaultCallback() {};"," this.settings = auto.extend( {}, auto.defaults, arguments.length === 3 ? settings : 'function' !== typeof callback ? callback : {} );"," this.response = {};"," this.listeners = [];"," this._meta = { started: new Date().getTime(), timeout: new Date().getTime() + this.settings.timeout };"," this.error = null;"," this.keys = Object.keys( this.tasks );",""," // Extend this with Event Emitter"," auto.emitter.mixin( this );",""," // Ensure there are tasks"," if( !this.keys.length ) {"," return callback( null );"," }",""," // Add to running queue"," auto.active[ this.id ] = this;",""," // Add final listener"," self.addListener( this.onComplete );",""," // Iterate through keys"," self.each( this.keys, this.taskIterator );",""," return this;","","}","","/**"," * Instance Properties."," *"," */","Object.defineProperties( auto.prototype, {"," taskIterator: {"," value: function taskIterator( key ) {",""," var self = this;"," var task = this.tasks[key] instanceof Function ? [ this.tasks[key] ] : this.tasks[key];"," var requires = task.slice( 0, Math.abs( task.length - 1 )) || [];",""," // Task Step Context"," var context = {"," id: self.id,"," task: key,"," requires: requires,"," response: self.response,"," tasks: self.tasks"," }",""," /**"," * Task Callback"," *"," * @todo Migrate into prototype."," * @param error"," */"," function taskCallback( error ) {",""," // Get response arguments"," var args = Array.prototype.slice.call( arguments, 1) ;",""," if (args.length <= 1) {"," args = args[0];"," }",""," if( error && error instanceof Error ) {"," var safeResults = {};",""," auto.each( Object.keys( self.response ), function( rkey ) {"," safeResults[rkey] = self.response[rkey];"," });",""," safeResults[key] = args;",""," // Emit task evnet and complete event"," self.emit( 'error', error, safeResults );"," self.emit( 'complete', error, safeResults );",""," // Remove from active queue"," delete auto.active[ this.id ];",""," // Trigger callback"," self.callback( error, safeResults );",""," // stop subsequent errors hitting callback multiple times"," self.callback = function __fake_callback__() {};",""," } else {",""," // Save task response to general response"," self.response[key] = args;",""," // process.nextTick( )"," self.setImmediate( self.stepComplete.bind( self ), key, args );",""," }",""," };",""," /**"," * Ready to Process a Step"," *"," * @todo Migrate into prototype."," * @returns {*|boolean}"," */"," function ready() {",""," // Identify Dependacncies with some form of magic"," var magic = self.reduce( requires, function( a, x ) {"," return ( a && self.response.hasOwnProperty( x ));"," }, true ) && !self.response.hasOwnProperty( key );",""," // Step Ready"," self.emit( 'ready', key, magic );",""," return magic;",""," };",""," // Trigger Method"," if( ready() ) {",""," task[ task.length - 1 ].bind( context )( taskCallback, self.response, self );",""," } else {",""," // Create a listener to be checked later"," self.addListener( function listener() {",""," if( ready() ) {"," self.removeListener( listener, key );"," task[ task.length - 1 ].bind( context )( taskCallback, self.response );"," }",""," }, key );",""," }",""," },"," writable: false,"," enumerable: false,"," configurable: true"," },"," onComplete: {"," value: function onComplete() {",""," if( Object.keys( this.response ).length !== this.keys.length ) {"," return;"," }",""," // Will fire multiple times if not checked"," if( this.callback.name === 'Placeholder' ) {"," return;"," }",""," // All steps in task are complete"," this.emit( 'complete', null, this.response );"," this.emit( 'success', this.response );",""," // Call the primary callback"," this.callback( null, this.response );",""," // Remove from active queue"," delete auto.active[ this.id ];",""," // Unset Callback"," this.callback = function Placeholder() {};",""," },"," writable: false,"," enumerable: false,"," configurable: true"," },"," removeListener: {"," /**"," * Remove Listener from Queue"," *"," * @method removeListener"," * @param fn"," * @param k"," */"," value: function removeListener( fn, k ) {"," // self.emit( 'removeListener', k );",""," for( var i = 0; i < this.listeners.length; i += 1 ) {"," if( this.listeners[i] === fn ) { this.listeners.splice(i, 1); return; }"," }",""," },"," writable: false,"," enumerable: false,"," configurable: true"," },"," setImmediate: {"," /**"," * Run Method on next tick"," *"," * @method setImmediate"," * @param fn"," * @returns {*}"," */"," value: function setImmediate( fn ) {",""," if( process && process.nextTick ) {"," return process.nextTick( fn );"," }",""," setTimeout( function() { fn() }, 0 )",""," },"," writable: false,"," enumerable: false,"," configurable: true"," },"," each: {"," /**"," * Array Iterator"," *"," * @method each"," * @param arr"," * @param iterator"," * @returns {*}"," */"," value: function each( arr, iterator ) {"," if (arr.forEach) { return arr.forEach( iterator.bind( this ) ); }"," for (var i = 0; i < arr.length; i += 1) { iterator.bind( this )(arr[i], i, arr); }"," },"," writable: false,"," enumerable: false,"," configurable: true"," },"," reduce: {"," /**"," * Array Reduce"," *"," * @method reduce"," * @param arr"," * @param iterator"," * @param memo"," * @returns {*}"," */"," value: function reduce( arr, iterator, memo ) {",""," if( arr.reduce) {"," return arr.reduce( iterator , memo);"," }",""," this.each( arr, function (x, i, a) {"," memo = iterator(memo, x, i, a);"," });",""," return memo;"," },"," writable: false,"," enumerable: false,"," configurable: true"," },"," addListener: {"," /**"," * Add Listener to Queue in context"," *"," * @method addListener"," * @param fn"," * @param k"," */"," value: function addListener( fn , k) {"," // self.emit( 'addListener', k );"," this.listeners.unshift( fn.bind( this ) );"," },"," writable: false,"," enumerable: false,"," configurable: true"," },"," stepComplete: {"," /**"," * Single Step Complete"," *"," * @method stepComplete"," * @param k"," * @param args"," */"," value: function stepComplete( k, args ) {"," // self.emit( 'step_complete', k, args );",""," // Get just the methods from each step"," this.each( this.listeners.slice(0), function( fn ) {"," fn();"," });",""," },"," writable: false,"," enumerable: false,"," configurable: true"," }","});","","/**"," * Constructor Properties"," *"," */","Object.defineProperties( module.exports = auto, {"," middleware: {"," /**"," *"," * @param tasks"," * @param callback"," * @param settings"," * @returns {Function}"," */"," value: function middleware( tasks, callback, settings ) {",""," return function middleware( req, res, next ) {",""," var instance = auto( tasks, callback, settings );",""," instance.on( 'success', function complete( report ) {"," res.send( report );"," });",""," instance.on( 'error', function error( error, report ) {"," next( error );"," });",""," }",""," },"," enumerable: true,"," writable: true,"," configurable: false"," },"," defaults: {"," value: {"," timeout: 5000"," },"," enumerable: true,"," writable: true,"," configurable: false"," },"," emitter: {"," value: require( 'object-emitter' ),"," writable: true,"," enumerable: false"," },"," extend: {"," value: require( 'extend' ),"," enumerable: false,"," writable: true"," },"," active: {"," value: {},"," enumerable: true,"," configurable: false,"," writable: true"," },","});"]; | ||
_$jscoverage['auto.js'].source = ["/**"," * auto Module"," *"," * -"," *"," * @module auto"," * @constructor"," * @author potanin@UD"," * @date 8/5/13"," * @type {Object}"," */","function auto( tasks, callback, settings ) {",""," // Ensure always using new instance of auto"," if( !( this instanceof auto ) ) {",""," if( arguments.length === 0 ) {"," return {};"," }",""," if( arguments.length === 1 ) {"," return new auto( tasks );"," }",""," if( arguments.length === 2 ) {"," return new auto( tasks, callback );"," }",""," if( arguments.length === 3 ) {"," return new auto( tasks, callback, settings );"," }",""," }",""," // Set private properties"," var self = this;",""," // Set instance properties"," self.id = Math.random().toString( 36 ).substring( 7 );"," self.tasks = tasks;"," self.callback = arguments[1] instanceof Function ? arguments[1] : function defaultCallback() {};"," self.settings = auto.extend( {}, auto.defaults, arguments.length === 3 ? settings : 'function' !== typeof callback ? callback : {} );"," self.response = {};"," self.listeners = [];"," self._meta = { started: new Date().getTime(), timeout: new Date().getTime() + self.settings.timeout };"," self.error = null;"," self.keys = Object.keys( self.tasks );",""," // Extend this with Event Emitter"," auto.emitter.mixin( self );",""," // Ensure there are tasks"," if( !self.keys.length ) {"," process.nextTick( function() { self.emit( 'complete', null, {} ); });"," return self.callback( null );"," }",""," // Add to running queue"," auto.active[ self.id ] = self;",""," // Add final listener"," self.addListener( self.onComplete );",""," // Iterate through keys"," self.each( self.keys, self.taskIterator );",""," return self;","","}","","/**"," * Instance Properties."," *"," */","Object.defineProperties( auto.prototype, {"," taskIterator: {"," value: function taskIterator( key ) {",""," var self = this;"," var task = this.tasks[key] instanceof Function ? [ this.tasks[key] ] : this.tasks[key];"," var requires = task.slice( 0, Math.abs( task.length - 1 )) || [];",""," // Task Step Context"," var context = {"," id: self.id,"," task: key,"," requires: requires,"," response: self.response,"," tasks: self.tasks"," }",""," /**"," * Task Callback"," *"," * @todo Migrate into prototype."," * @param error"," */"," function taskCallback( error ) {",""," // Get response arguments"," var args = Array.prototype.slice.call( arguments, 1) ;",""," if (args.length <= 1) {"," args = args[0];"," }",""," if( error && error instanceof Error ) {"," var safeResults = {};",""," auto.each( Object.keys( self.response ), function( rkey ) {"," safeResults[rkey] = self.response[rkey];"," });",""," safeResults[key] = args;",""," // Emit task evnet and complete event"," self.emit( 'error', error, safeResults );"," self.emit( 'complete', error, safeResults );",""," // Remove from active queue"," delete auto.active[ this.id ];",""," // Trigger callback"," self.callback( error, safeResults );",""," // stop subsequent errors hitting callback multiple times"," self.callback = function __fake_callback__() {};",""," } else {",""," // Save task response to general response"," self.response[key] = args;",""," // process.nextTick( )"," self.setImmediate( self.stepComplete.bind( self ), key, args );",""," }",""," };",""," /**"," * Ready to Process a Step"," *"," * @todo Migrate into prototype."," * @returns {*|boolean}"," */"," function ready() {",""," // Identify Dependacncies with some form of magic"," var magic = self.reduce( requires, function( a, x ) {"," return ( a && self.response.hasOwnProperty( x ));"," }, true ) && !self.response.hasOwnProperty( key );",""," // Step Ready"," self.emit( 'ready', key, magic );",""," return magic;",""," };",""," // Trigger Method"," if( ready() ) {",""," task[ task.length - 1 ].bind( context )( taskCallback, self.response, self );",""," } else {",""," // Create a listener to be checked later"," self.addListener( function listener() {",""," if( ready() ) {"," self.removeListener( listener, key );"," task[ task.length - 1 ].bind( context )( taskCallback, self.response );"," }",""," }, key );",""," }",""," },"," writable: false,"," enumerable: false,"," configurable: true"," },"," onComplete: {"," value: function onComplete() {",""," if( Object.keys( this.response ).length !== this.keys.length ) {"," return;"," }",""," // Will fire multiple times if not checked"," if( this.callback.name === 'Placeholder' ) {"," return;"," }",""," // All steps in task are complete"," this.emit( 'complete', null, this.response );"," this.emit( 'success', this.response );",""," // Call the primary callback"," this.callback( null, this.response );",""," // Remove from active queue"," delete auto.active[ this.id ];",""," // Unset Callback"," this.callback = function Placeholder() {};",""," },"," writable: false,"," enumerable: false,"," configurable: true"," },"," removeListener: {"," /**"," * Remove Listener from Queue"," *"," * @method removeListener"," * @param fn"," * @param k"," */"," value: function removeListener( fn, k ) {"," // self.emit( 'removeListener', k );",""," for( var i = 0; i < this.listeners.length; i += 1 ) {"," if( this.listeners[i] === fn ) { this.listeners.splice(i, 1); return; }"," }",""," },"," writable: false,"," enumerable: false,"," configurable: true"," },"," setImmediate: {"," /**"," * Run Method on next tick"," *"," * @method setImmediate"," * @param fn"," * @returns {*}"," */"," value: function setImmediate( fn ) {",""," if( process && process.nextTick ) {"," return process.nextTick( fn );"," }",""," setTimeout( function() { fn() }, 0 )",""," },"," writable: false,"," enumerable: false,"," configurable: true"," },"," each: {"," /**"," * Array Iterator"," *"," * @method each"," * @param arr"," * @param iterator"," * @returns {*}"," */"," value: function each( arr, iterator ) {"," if (arr.forEach) { return arr.forEach( iterator.bind( this ) ); }"," for (var i = 0; i < arr.length; i += 1) { iterator.bind( this )(arr[i], i, arr); }"," },"," writable: false,"," enumerable: false,"," configurable: true"," },"," reduce: {"," /**"," * Array Reduce"," *"," * @method reduce"," * @param arr"," * @param iterator"," * @param memo"," * @returns {*}"," */"," value: function reduce( arr, iterator, memo ) {",""," if( arr.reduce) {"," return arr.reduce( iterator , memo);"," }",""," this.each( arr, function (x, i, a) {"," memo = iterator(memo, x, i, a);"," });",""," return memo;"," },"," writable: false,"," enumerable: false,"," configurable: true"," },"," addListener: {"," /**"," * Add Listener to Queue in context"," *"," * @method addListener"," * @param fn"," * @param k"," */"," value: function addListener( fn , k) {"," // self.emit( 'addListener', k );"," this.listeners.unshift( fn.bind( this ) );"," },"," writable: false,"," enumerable: false,"," configurable: true"," },"," stepComplete: {"," /**"," * Single Step Complete"," *"," * @method stepComplete"," * @param k"," * @param args"," */"," value: function stepComplete( k, args ) {"," // self.emit( 'step_complete', k, args );",""," // Get just the methods from each step"," this.each( this.listeners.slice(0), function( fn ) {"," fn();"," });",""," },"," writable: false,"," enumerable: false,"," configurable: true"," }","});","","/**"," * Constructor Properties"," *"," */","Object.defineProperties( module.exports = auto, {"," middleware: {"," /**"," *"," * @param tasks"," * @param callback"," * @param settings"," * @returns {Function}"," */"," value: function middleware( tasks, callback, settings ) {",""," return function middleware( req, res, next ) {",""," var instance = auto( tasks, callback, settings );",""," instance.on( 'success', function complete( report ) {"," res.send( report );"," });",""," instance.on( 'error', function error( error, report ) {"," next( error );"," });",""," }",""," },"," enumerable: true,"," writable: true,"," configurable: false"," },"," defaults: {"," value: {"," timeout: 5000"," },"," enumerable: true,"," writable: true,"," configurable: false"," },"," emitter: {"," value: require( 'object-emitter' ),"," writable: true,"," enumerable: false"," },"," extend: {"," value: require( 'extend' ),"," enumerable: false,"," writable: true"," },"," active: {"," value: {},"," enumerable: true,"," configurable: false,"," writable: true"," },","});"]; |
109
test/api.js
@@ -24,7 +24,11 @@ /** | ||
var instance = auto(); | ||
instance.should.be.a( 'object' ); | ||
instance.should.be.an.instanceOf( Object ); | ||
Object.keys( instance ).length.should.equal( 0 ); | ||
// Tasks and settings will use default callback | ||
var instance = auto({ one: function( next, report ) { next( null, 'one done' ); } }, { test: true }); | ||
var instance = auto( { one: function( next, report ) { | ||
next( null, 'one done' ); | ||
} }, { test: true } ); | ||
instance.should.have.property( 'settings' ); | ||
@@ -36,5 +40,7 @@ instance.should.have.property( 'callback' ); | ||
// Tasks, callback and settings will use our callback and merge out settings with default | ||
var instance = auto({ one: function( next, report ) { next( null, 'one done' ); } }, function ourCallback() {}, { test: true } ); | ||
var instance = auto( { one: function( next, report ) { | ||
next( null, 'one done' ); | ||
} }, function ourCallback() { | ||
}, { test: true } ); | ||
instance.should.have.property( 'settings' ); | ||
@@ -56,3 +62,3 @@ instance.should.have.property( 'callback' ); | ||
var instance = auto({ | ||
var instance = auto( { | ||
one: function( next, report ) { | ||
@@ -79,3 +85,3 @@ // console.log( 'one' ); | ||
}], | ||
}); | ||
} ); | ||
@@ -86,4 +92,93 @@ instance.on( 'complete', done ); | ||
// console.log( 'event:', this.event, data ); | ||
}) | ||
} ) | ||
}, | ||
/** | ||
* Test Request Batching | ||
* | ||
* 100 records - 872ms | ||
* | ||
* @param done | ||
*/ | ||
'can batch.': function( test_done ) { | ||
this.timeout( 100000 ); | ||
var request = require( 'request' ); | ||
var auto = require( '../' ); | ||
var colors = require( 'colors' ); | ||
var querystring = require( 'querystring' ); | ||
var faker = require( 'faker' ).Helpers; | ||
var batch = auto.createBatch({ | ||
payload: 20, | ||
saturated: function saturated() { | ||
console.log( 'saturated' ); | ||
}, | ||
empty: function empty() { | ||
//console.log( 'empty' ); | ||
}, | ||
drain: function drain() { | ||
//console.log( 'drain' ); | ||
}, | ||
process: function process( items, batch_done ) { | ||
//console.log( 'Processing cars.' ); | ||
var body = []; | ||
var _header; | ||
// Build the crazy format ElasticSearch wants | ||
for( var i in items ) { | ||
body.push( JSON.stringify({ | ||
"index" : { | ||
"_index": items[i]._index || 'autobatch-test', | ||
"_type": items[i]._type || 'user-card', | ||
"_id": items[i]._id || null | ||
} | ||
}) ); | ||
body.push( JSON.stringify( items[i], false, 0 ) ); | ||
} | ||
request({ | ||
url: 'http://localhost:9200/_bulk', | ||
method: 'post', | ||
json: true, | ||
headers: {}, | ||
body: body.join( "\n" ) + "\n" | ||
}, function( error, res, body ) { | ||
body.should.have.property( 'took' ); | ||
body.should.have.property( 'items' ); | ||
batch_done( null, res, body ); | ||
//test_done() | ||
}); | ||
} | ||
}); | ||
require( 'async' ).timesSeries( 100, function( n, next ) { | ||
batch.push( faker.createCard(), function done( error, response, body ) { | ||
//console.log( 'Processed [%d] items in [%d].', body.items.length, body.took ); | ||
//console.log( error ? error.message : 'Added item [%s].', body ? body.items[0].index._id : null ); | ||
}); | ||
setTimeout( function() { | ||
next( null, true ); | ||
}, 10 ) | ||
//console.log( batch.payload ); | ||
}, function( error, items ) { | ||
//console.log( 'done', items.length ); | ||
test_done() | ||
}); | ||
} | ||
@@ -90,0 +185,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
44
0
100
2813
176352
4
4
+ Addedasync@~0.2.9
+ Addedforeign-key@~0.1.0
+ Addedasync@0.2.10(transitive)
+ Addedbytewise@0.5.0(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedes6-shim@0.35.8(transitive)
+ Addedforeign-key@0.1.0(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedreadable-stream@1.0.34(transitive)
+ Addedstring_decoder@0.10.31(transitive)
- Removedasync@3.2.6(transitive)