versao nrgocios
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-10-16 13:06:58 +02:00
parent 6a76aac80f
commit 2d23157e40
17260 changed files with 4150820 additions and 43 deletions
@@ -0,0 +1,4 @@
support
test
examples
*.sock
@@ -0,0 +1,93 @@
0.6.1 / 2017-05-16
==================
* fix `process.nextTick` detection in Node.js
0.6.0 / 2017-03-25
==================
* always invoke end callback asynchronously
* fix compatibility with component v1
* fix license field
0.5.3 / 2015-10-01
==================
* fix for browserify
0.5.2 / 2014-12-22
==================
* add brower field
* add license to package.json
0.5.1 / 2014-06-19
==================
* add repository field to readme (exciting)
0.5.0 / 2013-07-29
==================
* add `.throws(true)` to opt-in to responding with an array of error objects
* make `new` optional
0.4.0 / 2013-06-05
==================
* add catching of immediate callback errors
0.3.2 / 2013-03-15
==================
* remove Emitter call in constructor
0.3.1 / 2013-03-13
==================
* add Emitter() mixin for client. Closes #8
0.3.0 / 2013-03-13
==================
* add component.json
* add result example
* add .concurrency support
* add concurrency example
* add parallel example
0.2.1 / 2012-11-08
==================
* add .start, .end, and .duration properties
* change dependencies to devDependencies
0.2.0 / 2012-10-04
==================
* add progress events. Closes #5 (__BREAKING CHANGE__)
0.1.1 / 2012-07-03
==================
* change "complete" event to "progress"
0.1.0 / 2012-07-03
==================
* add Emitter inheritance and emit "complete" [burcu]
0.0.3 / 2012-06-02
==================
* Callback results should be in the order of the queued functions.
0.0.2 / 2012-02-12
==================
* any node
0.0.1 / 2010-01-03
==================
* Initial release
@@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) 2013 TJ Holowaychuk <tj@vision-media.ca>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,6 @@
test:
@./node_modules/.bin/mocha \
--require should
.PHONY: test
@@ -0,0 +1,53 @@
# batch
Simple async batch with concurrency control and progress reporting.
## Installation
```
$ npm install batch
```
## API
```js
var Batch = require('batch')
, batch = new Batch;
batch.concurrency(4);
ids.forEach(function(id){
batch.push(function(done){
User.get(id, done);
});
});
batch.on('progress', function(e){
});
batch.end(function(err, users){
});
```
### Progress events
Contain the "job" index, response value, duration information, and completion data.
```
{ index: 1,
value: 'bar',
pending: 2,
total: 3,
complete: 2,
percent: 66,
start: Thu Oct 04 2012 12:25:53 GMT-0700 (PDT),
end: Thu Oct 04 2012 12:25:53 GMT-0700 (PDT),
duration: 0 }
```
## License
[MIT](LICENSE)
@@ -0,0 +1,14 @@
{
"name": "batch",
"repo": "visionmedia/batch",
"description": "Async task batching",
"version": "0.6.1",
"keywords": ["batch", "async", "utility", "concurrency", "concurrent"],
"dependencies": {
"component/emitter": "*"
},
"development": {},
"scripts": [
"index.js"
]
}
@@ -0,0 +1,173 @@
/**
* Module dependencies.
*/
try {
var EventEmitter = require('events').EventEmitter;
if (!EventEmitter) throw new Error();
} catch (err) {
var Emitter = require('emitter');
}
/**
* Defer.
*/
var defer = typeof process !== 'undefined' && process && typeof process.nextTick === 'function'
? process.nextTick
: function(fn){ setTimeout(fn); };
/**
* Noop.
*/
function noop(){}
/**
* Expose `Batch`.
*/
module.exports = Batch;
/**
* Create a new Batch.
*/
function Batch() {
if (!(this instanceof Batch)) return new Batch;
this.fns = [];
this.concurrency(Infinity);
this.throws(true);
for (var i = 0, len = arguments.length; i < len; ++i) {
this.push(arguments[i]);
}
}
/**
* Inherit from `EventEmitter.prototype`.
*/
if (EventEmitter) {
Batch.prototype.__proto__ = EventEmitter.prototype;
} else {
Emitter(Batch.prototype);
}
/**
* Set concurrency to `n`.
*
* @param {Number} n
* @return {Batch}
* @api public
*/
Batch.prototype.concurrency = function(n){
this.n = n;
return this;
};
/**
* Queue a function.
*
* @param {Function} fn
* @return {Batch}
* @api public
*/
Batch.prototype.push = function(fn){
this.fns.push(fn);
return this;
};
/**
* Set wether Batch will or will not throw up.
*
* @param {Boolean} throws
* @return {Batch}
* @api public
*/
Batch.prototype.throws = function(throws) {
this.e = !!throws;
return this;
};
/**
* Execute all queued functions in parallel,
* executing `cb(err, results)`.
*
* @param {Function} cb
* @return {Batch}
* @api public
*/
Batch.prototype.end = function(cb){
var self = this
, total = this.fns.length
, pending = total
, results = []
, errors = []
, cb = cb || noop
, fns = this.fns
, max = this.n
, throws = this.e
, index = 0
, done;
// empty
if (!fns.length) return defer(function(){
cb(null, results);
});
// process
function next() {
var i = index++;
var fn = fns[i];
if (!fn) return;
var start = new Date;
try {
fn(callback);
} catch (err) {
callback(err);
}
function callback(err, res){
if (done) return;
if (err && throws) return done = true, defer(function(){
cb(err);
});
var complete = total - pending + 1;
var end = new Date;
results[i] = res;
errors[i] = err;
self.emit('progress', {
index: i,
value: res,
error: err,
pending: pending,
total: total,
complete: complete,
percent: complete / total * 100 | 0,
start: start,
end: end,
duration: end - start
});
if (--pending) next();
else defer(function(){
if(!throws) cb(errors, results);
else cb(null, results);
});
}
}
// concurrency
for (var i = 0; i < fns.length; i++) {
if (i == max) break;
next();
}
return this;
};
@@ -0,0 +1,19 @@
{
"name": "batch",
"description": "Simple async batch with concurrency control and progress reporting.",
"version": "0.6.1",
"author": "TJ Holowaychuk <tj@vision-media.ca>",
"license": "MIT",
"devDependencies": {
"mocha": "*",
"should": "*"
},
"main": "index",
"browser": {
"emitter": "events"
},
"repository": {
"type": "git",
"url": "https://github.com/visionmedia/batch.git"
}
}