????JFIF??x?x????'
| Server IP : 172.67.174.47 / Your IP : 216.73.216.145 Web Server : LiteSpeed System : Linux premium151.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64 User : tempvsty ( 647) PHP Version : 8.0.30 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /././././opt/alt/alt-nodejs9/root/usr/lib/node_modules/npm/node_modules/call-limit/ |
Upload File : |
"use strict"
var defaultMaxRunning = 50
var limit = module.exports = function (func, maxRunning) {
var running = 0
var queue = []
if (!maxRunning) maxRunning = defaultMaxRunning
return function limited () {
var self = this
var args = Array.prototype.slice.call(arguments)
if (running >= maxRunning) {
queue.push({self: this, args: args})
return
}
var cb = typeof args[args.length-1] === 'function' && args.pop()
++ running
args.push(function () {
var cbargs = arguments
-- running
cb && process.nextTick(function () {
cb.apply(self, cbargs)
})
if (queue.length) {
var next = queue.shift()
limited.apply(next.self, next.args)
}
})
func.apply(self, args)
}
}
module.exports.method = function (classOrObj, method, maxRunning) {
if (typeof classOrObj === 'function') {
var func = classOrObj.prototype[method]
classOrObj.prototype[method] = limit(func, maxRunning)
} else {
var func = classOrObj[method]
classOrObj[method] = limit(func, maxRunning)
}
}
module.exports.promise = function (func, maxRunning) {
var running = 0
var queue = []
if (!maxRunning) maxRunning = defaultMaxRunning
return function () {
var self = this
var args = Array.prototype.slice.call(arguments)
return new Promise(function (resolve) {
if (running >= maxRunning) {
queue.push({self: self, args: args, resolve: resolve})
return
} else {
runNext(self, args, resolve)
}
function runNext (self, args, resolve) {
++ running
resolve(
func.apply(self, args)
.then(finish, function (err) {
finish(err)
throw err
}))
}
function finish () {
-- running
if (queue.length) {
var next = queue.shift()
process.nextTick(runNext, next.self, next.args, next.resolve)
}
}
})
}
}
module.exports.promise.method = function (classOrObj, method, maxRunning) {
if (typeof classOrObj === 'function') {
var func = classOrObj.prototype[method]
classOrObj.prototype[method] = limit.promise(func, maxRunning)
} else {
var func = classOrObj[method]
classOrObj[method] = limit.promise(func, maxRunning)
}
}