Socket
Socket
Sign inDemoInstall

throat

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

throat - npm Package Compare versions

Comparing version 0.0.0 to 1.0.0

.travis.yml

95

index.js

@@ -1,67 +0,46 @@

var promise = require('promises-a');
'use strict'
module.exports = throttler;
function throttler(concurrency) {
var inProgress = 0;
var queue = [];
function throttle(fn) {
if (typeof fn != 'function') {
return reject(new TypeError(fn + ' is not a function.'));
}
if (idle() > 0) {
var result = fn();
inProgress++;
result.then(null, function () {})
.then(function () {
inProgress--;
if (queue.length) {
queue.shift()();
}
});
return result;
var Promise = require('promise')
module.exports = throat
function throat(size, fn) {
var queue = []
function run(fn, self, args) {
if (size) {
size--
var result = new Promise(function (resolve) {
resolve(fn.apply(self, args))
})
result.done(release, release)
return result
} else {
var def = promise();
queue.push(function () {
def.fulfill(throttle(fn));
});
return def.promise;
return new Promise(function (resolve) {
queue.push(new Delayed(resolve, fn, self, args))
})
}
}
throttle.workers = workers;
function workers(val) {
if (typeof val === 'number')
return concurrency = val;
else return concurrency;
function release() {
size++
if (queue.length) {
var next = queue.shift()
next.resolve(run(next.fn, next.self, next.args))
}
}
throttle.running = running;
function running() {
return inProgress;
if (typeof fn === 'function') {
return function () {
var args = arguments
return run(fn, this, arguments)
}
} else {
return function (fn) {
return run(fn, this, Array.prototype.slice.call(arguments, 1))
}
}
throttle.idle = idle;
function idle() {
return concurrency - inProgress;
}
throttle.workOn = function (source, worker) {
var def = promise();
function nextJob() {
throttle(function () {
return source()
.then(function (job) {
nextJob();
return worker(job);
});
})
.then(null, def.reject);
}
nextJob();
return def.promise;
};
return throttle;
}
function reject(reason) {
var p = promise();
p.reject(reason);
return p.promise;
function Delayed(resolve, fn, self, args) {
this.resolve = resolve
this.fn = fn
this.self = self || null
this.args = args || null
}
{
"name": "throat",
"version": "0.0.0",
"description": "Throttle a collection of promise returning functions",
"main": "index.js",
"scripts": {
"test": "mocha -R spec"
},
"repository": {
"type": "git",
"url": "https://github.com/ForbesLindesay/throat.git"
},
"version": "1.0.0",
"description": "Throttle the parallelism of an asynchronous (promise returning) function / functions",
"keywords": [

@@ -19,13 +11,20 @@ "promise",

"concurrency",
"parallelism",
"limit"
],
"author": "ForbesLindesay",
"license": "MIT",
"dependencies": {
"promises-a": "~2"
"promise": "~3.2.0"
},
"devDependencies": {
"mocha": "~1",
"better-assert": "~0.1.0"
}
}
"mocha": "*"
},
"scripts": {
"test": "mocha -R spec"
},
"repository": {
"type": "git",
"url": "https://github.com/ForbesLindesay/throat.git"
},
"author": "ForbesLindesay",
"license": "MIT"
}

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