Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-batch

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-batch - npm Package Compare versions

Comparing version 0.3.3 to 0.4.0

37

index.js
'use strict';
var es = require('event-stream');
module.exports = function (opts, cb) {

@@ -26,14 +28,20 @@ if (typeof opts === 'function') {

function async(err) {
if (err) { holdOn = false; throw err; }
function async() {
holdOn = true;
return function (err) {
if (err) {
holdOn = false;
return domain.emit('error', err);
}
if (opts.debounce) {
setTimeout(function () {
if (opts.debounce) {
setTimeout(function () {
holdOn = false;
brace();
}, opts.debounce);
} else {
holdOn = false;
brace();
}, opts.debounce);
} else {
holdOn = false;
brace();
}
}
};
}

@@ -45,10 +53,13 @@

if (!batch.length) { return; }
var _batch = batch;
var _batch = es.readArray(batch);
batch = [];
if (cb.length < 2) {
process.nextTick(function () { domain.bind(cb)(_batch); });
var r = domain.bind(cb)(_batch);
if (r && typeof r.pipe === 'function') {
// wait for stream to end
r.pipe(es.wait(async()));
}
} else {
holdOn = true;
process.nextTick(function () { domain.bind(cb)(_batch, async); });
domain.bind(cb)(_batch, async());
}

@@ -55,0 +66,0 @@ }

{
"name": "gulp-batch",
"version": "0.3.3",
"version": "0.4.0",
"description": "Event batcher for gulp-watcher",

@@ -16,3 +16,4 @@ "main": "index.js",

"scripts": {
"test": "gulp mocha"
"test": "istanbul test _mocha --report html -- test/*.js --reporter spec",
"coveralls": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
},

@@ -30,2 +31,6 @@ "repository": {

"gulp": "~3.2.2",
"coveralls": "~2.6.0",
"mocha": "~1.14.0",
"mocha-lcov-reporter": "0.0.1",
"istanbul": "~0.1.44",
"gulp-mocha": "~0.2.0",

@@ -35,3 +40,6 @@ "espower-loader": "~0.3.1",

"async": "~0.2.9"
},
"dependencies": {
"event-stream": "~3.1.0"
}
}

@@ -1,2 +0,2 @@

# [gulp](https://github.com/gulpjs/gulp)-batch [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][depstat-image]][depstat-url]
# [gulp](https://github.com/gulpjs/gulp)-batch [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status](https://coveralls.io/repos/floatdrop/gulp-batch/badge.png)](https://coveralls.io/r/floatdrop/gulp-batch) [![Dependency Status][depstat-image]][depstat-url]
> Event batcher for gulp-watch'er.

@@ -21,10 +21,5 @@

gulp.task('mocha', function () {
return gulp.src(['test/*.js'])
.pipe(mocha({ reporter: 'list' }))
.on('error', gutil.log);
});
gulp.src(['lib/**', 'test/**'], batch(function(events, cb) {
gulp.run('mocha', cb);
gulp.src(['lib/**', 'test/**'], batch(function(events) {
return events
.pipe(mocha({ reporter: 'list' }));
}));

@@ -43,3 +38,3 @@ ```

* `events` - is `Array` of incoming events.
* `events` - is `Stream` of incoming events.
* `done` - is callback for your function signal to batch, that you are done. This allows to run your callback as soon as previous end. Error can be passed as argument.

@@ -94,2 +89,2 @@

[depstat-url]: https://david-dm.org/floatdrop/gulp-batch
[depstat-image]: https://david-dm.org/floatdrop/gulp-batch.png
[depstat-image]: https://david-dm.org/floatdrop/gulp-batch.png?theme=shields.io

@@ -7,5 +7,32 @@ /* global describe, it */

var assert = require('power-assert');
var es = require('event-stream');
var async = require('async');
var defaultTimeout = 10,
defaultDebounce = 10;
describe('glob-batch', function () {
it('should attach holdOff to stream end', function (done) {
var signal = false;
var receiver = batch({ timeout: defaultTimeout }, function (events) {
return events.pipe(es.map(function (data, cb) {
if (signal) { done(new Error('Tasks was started parallel')); }
if (!signal && data === 'two') { done(); }
signal = true;
setTimeout(function () {
signal = false;
cb();
}, 20);
}));
});
receiver('one');
setTimeout(receiver.bind(receiver, 'two'), 15);
});
it('should swap callback, if options omitted', function (done) {
var receiver = batch(function () { done(); });
receiver('one');
});
it('should support domains `on(\'error\', ...)` without callback', function (done) {

@@ -17,3 +44,3 @@ var domain = require('domain').create();

});
var receiver = domain.bind(batch({ timeout: 10 }, function () {
var receiver = domain.bind(batch({ timeout: defaultTimeout }, function () {
throw new Error('Bang!');

@@ -24,2 +51,14 @@ }));

it('should support domains `on(\'error\', ...)` without callback', function (done) {
var domain = require('domain').create();
domain.on('error', function (err) {
assert.ok(err);
done();
});
var receiver = domain.bind(batch({ timeout: defaultTimeout }, function () {
throw new Error('Bang!');
}));
receiver('one');
});
it('should support domains `on(\'error\', ...)` with callback', function (done) {

@@ -31,3 +70,3 @@ var domain = require('domain').create();

});
var receiver = domain.bind(batch({ timeout: 10 }, function (events, async) {
var receiver = domain.bind(batch({ timeout: defaultTimeout }, function (events, async) {
async(new Error('Bang!'));

@@ -44,3 +83,3 @@ }));

});
var receiver = domain.bind(batch({ timeout: 10 }, function (events, async) {
var receiver = domain.bind(batch({ timeout: defaultTimeout }, function (events, async) {
throw new Error('Bang!');

@@ -51,5 +90,7 @@ }));

it('should batch sync calls to array', function (done) {
var receiver = batch({ timeout: 10 }, function (events) {
assert.equal(events.length, 2);
it('should batch sync calls to stream', function (done) {
var receiver = batch({ timeout: defaultTimeout }, function (events) {
events.pipe(es.writeArray(function (err, array) {
assert.equal(array.length, 2);
}));
done();

@@ -61,5 +102,7 @@ });

it('should batch async calls to array', function (done) {
var receiver = batch({ timeout: 10 }, function (events) {
assert.equal(events.length, 2);
it('should batch async calls to stream', function (done) {
var receiver = batch({ timeout: defaultTimeout }, function (events) {
events.pipe(es.writeArray(function (err, array) {
assert.equal(array.length, 2);
}));
done();

@@ -73,3 +116,7 @@ });

var iterator = async.iterator([
function (events) { assert.equal(events.length, 1); },
function (events) {
events.pipe(es.writeArray(function (err, array) {
assert.equal(array.length, 1);
}));
},
function () { done(); }

@@ -83,3 +130,3 @@ ]);

receiver('one');
setTimeout(receiver.bind(null, 'two'), 10);
setTimeout(receiver.bind(null, 'two'), defaultTimeout);
});

@@ -89,9 +136,15 @@

var iterator = async.iterator([
function (events) { assert.equal(events.length, 2); },
function (events) {
assert.equal(events.length, 1);
events.pipe(es.writeArray(function (err, array) {
assert.equal(array.length, 2);
}));
},
function (events) {
events.pipe(es.writeArray(function (err, array) {
assert.equal(array.length, 1);
}));
done();
}
]);
var receiver = batch({ timeout: 10, limit: 2 }, function (events) {
var receiver = batch({ timeout: defaultTimeout, limit: 2 }, function (events) {
iterator = iterator(events);

@@ -114,7 +167,9 @@ });

function (events) {
assert.equal(events.length, 2);
events.pipe(es.writeArray(function (err, array) {
assert.equal(array.length, 2);
}));
done();
}
]);
var receiver = batch({ timeout: 10 }, function (events, cb) {
var receiver = batch({ timeout: defaultTimeout }, function (events, cb) {
iterator = iterator(events, cb);

@@ -135,7 +190,9 @@ });

function (events) {
assert.equal(events.length, 2);
events.pipe(es.writeArray(function (err, array) {
assert.equal(array.length, 2);
}));
done();
}
]);
var receiver = batch({ timeout: 10, debounce: 10 }, function (events, cb) {
var receiver = batch({ timeout: defaultTimeout, debounce: defaultDebounce }, function (events, cb) {
iterator = iterator(events, cb);

@@ -142,0 +199,0 @@ });

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc