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

enqueue

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

enqueue - npm Package Compare versions

Comparing version 0.0.4 to 1.0.0

components/visionmedia-co@3.1.0/History.md

2

component.json

@@ -5,3 +5,3 @@ {

"description": "queue up async function calls without the overhead",
"version": "0.0.4",
"version": "1.0.0",
"keywords": [],

@@ -8,0 +8,0 @@ "dependencies": {},

1.0.0 / 2015-03-19
==================
* BREAKING: 2nd arg is now an options object, not a number for concurrency
* fix: queued items without a callback
* add: timeout support.
* update: .gitignore
0.0.4 / 2014-08-31

@@ -3,0 +11,0 @@ ==================

@@ -5,3 +5,4 @@ /**

var slice = [].slice;
var sliced = require('sliced');
var noop = function(){};

@@ -18,7 +19,10 @@ /**

* @param {Function} fn
* @param {Number} concurrency
* @param {Object} options
*/
function enqueue(fn, concurrency) {
concurrency = concurrency || 1;
function enqueue(fn, options) {
options = options || {};
var concurrency = options.concurrency || 1;
var timeout = options.timeout || false;
var pending = 1;

@@ -28,13 +32,10 @@ var jobs = [];

return function() {
var args = slice.call(arguments);
var args = sliced(arguments);
var last = args[args.length - 1];
var cb = 'function' == typeof last && last;
var end = 'function' == typeof last && last;
var ctx = this;
// replace original callback with done
if (cb) {
args.pop();
args.push(done);
}
jobs.push([fn, this, args]);
// remove "on end" function if there is one
end = end ? args.pop() : noop;
jobs.push([ctx, args.concat(once(done))]);
return next();

@@ -46,12 +47,39 @@

if (!job) return;
var ctx = job[0];
var args = job[1];
var finish = args[args.length - 1];
pending++;
return job[0].apply(job[1], job[2]);
// support timeouts
if (timeout) {
setTimeout(function() {
finish(new Error('job timed out'))
}, timeout);
}
// call the fn
return fn.apply(job[0], job[1]);
}
function done(fn) {
function done() {
pending--;
next();
return cb.apply(this, arguments);
return end.apply(this, arguments);
}
}
}
/**
* Once
*/
function once(fn) {
var called = false;
return function _once() {
if (called) return noop();
called = true;
return fn.apply(this, arguments);
}
}
{
"name": "enqueue",
"version": "0.0.4",
"version": "1.0.0",
"description": "queue up function calls",

@@ -11,3 +11,5 @@ "keywords": [],

},
"dependencies": {},
"dependencies": {
"sliced": "0.0.5"
},
"devDependencies": {

@@ -14,0 +16,0 @@ "mocha": "*"

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